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