1. 程式人生 > >Matlab - 將字符串作為代碼執行

Matlab - 將字符串作為代碼執行

inpu quest fun 執行 variable als div 循環結構 atl

使用eval()函數將字符串作為代碼執行;

配合num2str()函數和循環結構,可訪問按規律排列的文件。

>> help eval

eval Execute MATLAB expression in text.

% eval 將字符作為MATLAB代碼執行;

eval(EXPRESSION) evaluates the MATLAB code in the character vector EXPRESSION. [OUTPUT1,...,OUTPUTN] = eval(EXPRESSION) returns output from EXPRESSION in the specified variables. %例 Example: Interactively request the name of a matrix to plot. expression = input(‘Enter the name of a matrix: ‘,‘s‘); if (exist(expression,‘var‘)) plot(eval(expression)) end See also feval, evalin, assignin, evalc. Reference page for eval Other functions named eval

Matlab - 將字符串作為代碼執行