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基本一样了.