MATLAB中如何在字符串中加空格

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qjt19950610/article/details/83050869

以下是刚开始X轴标题没有空格的代码。

x=-2:0.2:2;
y=x.^2;
plot(x,y)
str1=num2str(min(x));
str2=num2str(max(x));
out=['value of  from'  str1   'to'   str2];
xlabel(out);

就是不管你上面有多少个空格都不会打印出来。原因是空格是一个字符需要用‘ ’。这就是错误的原因,另外用‘ ’比较麻烦。其实可以用strvcat函数来解决。 

a='value of  from';
out=strcat(a,32, str1,32,'to',32,str2);

OK,这就解决了。

猜你喜欢

转载自blog.csdn.net/qjt19950610/article/details/83050869