使用figure命令(MATLAB)连接字符串

时间:2016-03-25 19:06:55

标签: string matlab concatenation matlab-figure string-concatenation

我试图连接字符串,当我像这样单独连接它们时:

strcat({'Plot of f with a plot of iterates for c='},{int2str(c)})

没有错误。

但是当我尝试在图形命令中使用它们时,这样:

 figure('Name',strcat({'Plot of f with a plot of iterates for c='},{int2str(c)}))

我收到此错误:

Error using figure
Value must be a string

这有什么原因吗?

2 个答案:

答案 0 :(得分:2)

正如@Matthias W.所指出的,strcat({'Plot of f with a plot of iterates for c='},{int2str(c)})的输出是1x1 cell,而不是figure()函数所期望的字符串。

尝试以下

figure('Name',['Plot of f with a plot of iterates for c=', int2str(c)])

答案 1 :(得分:1)

使用[] s进行字符串连接是一个很好的简短解决方案。由于您已经在进行转换,因此您也可以考虑学习sprintf

figure('Name', sprintf('Plot of f with a plot of iterates for c = %d.\n', c));

在这个例子中这可能有点过头了,但是如果您需要打印出许多值,或者想要更多地控制数字的显示方式,这可能是值得的。