2.脚本没有参数的输入输出,函数有。
3.使用函数,需要一个脚本或者函数召唤它。
1. MATLAB scripts and functions are .m files containing MATLAB commands.2. The script has no input and output parameters, but the function has.3. To use a function, you need a script or function to call it.Part 2查看内嵌函数如查看平均数函数Such as viewing the average function通过上述内嵌函数,我们可以看到函数设置的五个要素:Through the above embedded function, we can see the five elements of the function setting:1.函数使用的关键字是function2.文件名与函数名字是一致的3.(x,dim,flag)是输入,y是输出4.dim和flag为局部变量5.MATLAB需要有找到该函数的路径1. The keyword used by the function is function2. The file name is consistent with the function name3. (x, dim, flag) is input, y is output4.dim and flag are local variables5. MATLAB needs a path to find the functionPart 3用户自定义函数如自定义自由落体位移函数Such as custom free fall displacement function首先新建脚本,输入函数,保存为与函数名相同名字的文件。
First create a new script, enter the function, and save it as a file with the same name as the function.注意:元素与元素之间是点乘。
然后就可以调用该函数了。
Note: There is a dot product between elements.Then you can call the function.调用内嵌函数和自定义函数是一致的。
例如可以计算两组数据。
Calling built-in functions is consistent with custom functions. For example, two sets of data can be calculated.Part 4多输入、多输出函数如定义下列函数Such as defining the following function然后调用函数Then call the function我们会发现结果不对,多输入多输出函数的正确使用方法如下:We will find that the result is wrong. The correct way to use the multiple-input multiple-output function is as follows:Part 5没有input函数例如,在命令栏输入一个华氏温度,然后计算成摄氏温度。
For example, enter a Fahrenheit temperature in the command bar, and then calculate it to Celsius.Isempty:判断该函数是否为空Num2str:将数值转化为字符串然后运行程序,不停的输入,结果如下:Isempty: Determine whether the function is emptyNum2str: Convert a value to a stringThen run the program, keep typing, the results are as follows:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)