
Part 1
Matlab函數的基本概念
1.MATLAB的腳本和函數都是包含MATLAB命令的.m文件。
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.函數使用的關鍵字是function
2.文件名與函數名字是一致的
3.(x,dim,flag)是輸入,y是輸出
4.dim和flag為局部變量
5.MATLAB需要有找到該函數的路徑
1. The keyword used by the function is function
2. The file name is consistent with the function name
3. (x, dim, flag) is input, y is output
4.dim and flag are local variables
5. MATLAB needs a path to find the function
Part 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 empty
Num2str: Convert a value to a string
Then run the program, keep typing, the results are as follows:

原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/281994.html
微信掃一掃
支付寶掃一掃