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


使用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
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM