How to display with n decimal places in Matlab

喜欢而已 提交于 2019-12-18 15:51:29

问题


I was wondering how to use command to set up displaying with n decimal places in Matlab?

Must n be restricted to some predetermined numbers? Or one can just specify any for n?

Thanks and regards!


回答1:


You can convert a number to a string with n decimal places using the SPRINTF command:

>> x = 1.23;
>> sprintf('%0.6f', x)

ans =

1.230000

>> x = 1.23456789;
>> sprintf('%0.6f', x)

ans =

1.234568



回答2:


This site might help you out with all of that:

http://herz-fischler.ca/MATLAB/section15.html




回答3:


i use like tim say sprintf('%0.6f', x), it's a string then i change it to number by using command str2double(x).



来源:https://stackoverflow.com/questions/5149348/how-to-display-with-n-decimal-places-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!