Matlab - 将字符串作为代码执行

Posted Super_Jian

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

以上是关于Matlab - 将字符串作为代码执行的主要内容,如果未能解决你的问题,请参考以下文章