Matlab中的输出命令~向高手求救~

来源:百度知道 编辑:UC知道 时间:2024/06/24 07:48:26
Matlab能实现如C++中能实现的如“cout<<'某字符串'<<x”的功能吗?其中x是某个变量。我的意思是输出时把字符串和x的值输出在同一行。disp函数只能输出某个矩阵的值或是某个字符串,但不能同时输出这两种类型吧?

Command
Result
sprintf('%0.5g',(1+sqrt(5))/2) 1.618
sprintf('%0.5g',1/eps) 4.5036e+15
sprintf('%15.5f',1/eps) 4503599627370496.00000
sprintf('%d',round(pi)) 3
sprintf('%s','hello') hello
sprintf('The array is %dx%d.',2,3) The array is 2x3
sprintf('\n') Line termination character on all platforms
sprintf函数和C的printf差不多,上面是帮助里的例子,你看看吧.cout比较灵活,但MATLAB主要是从C那里学来的.
sprintf('The array is %dx%d.',2,3) The array is 2x3
这句就和C基本一样了.