Question About Number Format in MATLAB Command Window
1 次查看(过去 30 天)
显示 更早的评论
% I would like to display a number as a short format. I already executed this command:
format short
% However it doesn't work for some cases. For example, I receive this result:
>> pi
ans =
3.1416
% But I have another variable which I got from solutions of a polynomial.("roots" command)
% If I display those solutions,
% I get long number results. It looks like this:
>> format short
>> disp(x1_sols)
0.74613506773662727719908766254638
0.74624784618189352426025884090749
0.77735277675703701413872152754508
0.82647611867148647532781596815636
1.0679165995745538795723120147744
1.3550488761820195655871374504513
% How can I get short form of this?
% Thank you in advance.
0 个评论
采纳的回答
John D'Errico
2021-1-14
编辑:John D'Errico
2021-1-14
These are numbers from the symbolic toolbox. That toolbox does not use the format tools to display numbers (though perhaps arguably it could, but that would introduce a whole new set of problms.) You can use vpa to do that.
XX = vpa(1./sym([2;3;7;11;13]))
XX =
0.5
0.33333333333333333333333333333333
0.14285714285714285714285714285714
0.090909090909090909090909090909091
0.076923076923076923076923076923077
vpa(XX,4)
ans =
0.5
0.3333
0.1429
0.09091
0.07692
3 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!