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:
參考資料:百度百科、B站郭彥甫Matlab教程、谷歌翻譯