MATLAB 字符串操作与转换全解析
1. 字符串求值函数 eval
在 MATLAB 中, eval 函数用于将字符串作为函数进行求值。例如:
x = [2 6 8 3];
eval('plot(x)')
上述代码中,字符串 'plot(x)' 被解释为对 plot 函数的调用,从而生成相应的图形。
当用户输入要使用的绘图类型时, eval 函数会更加有用。示例如下:
x = [2 6 8 3];
whatplot = input('What type of plot?: ', 's');
eval([whatplot '(x)'])
title(whatplot)
若用户输入 bar ,则会生成一个条形图,并且图形的标题为 bar 。
实践 6.5
思考以下表达式和语句的返回结果,并在 MATLAB 中验证:
strcmp('hello', 'height')
strncmp('hello', 'height',2)
strncmpi('yes', 'YES', 1)
name = 'Smith, Carly';
ind = findstr(name,',')
first
超级会员免费看
订阅专栏 解锁全文
11

被折叠的 条评论
为什么被折叠?



