码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-09-23 12:29:52      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:func   fun   使用   排列   example   pre   variables   nbsp   matrix   

使用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 - 将字符串作为代码执行

标签:func   fun   使用   排列   example   pre   variables   nbsp   matrix   

原文地址:http://www.cnblogs.com/Jian-thinker/p/7580580.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!