How to format matrix to 4 decimal places in engineering notation:
3 次查看(过去 30 天)
显示 更早的评论
Hi, I have calculated this matrix:
[ 206043.95604395602131262421607971, 0, -206043.95604395602131262421607971, 82417.582417582406196743249893188, 0, -82417.582417582406196743249893188]
[ 0, 72115.384615384603966958820819855, 96153.84615384613862261176109314, -72115.384615384603966958820819855, -96153.84615384613862261176109314, 0]
[ -206043.95604395602131262421607971, 96153.84615384613862261176109314, 334249.08424908420614277323087056, -178571.42857142854481935501098633, -128205.12820512818483014901479085, 82417.582417582406196743249893188]
[ 82417.582417582406196743249893188, -72115.384615384603966958820819855, -178571.42857142854481935501098633, 438415.75091575086407829076051712, 96153.84615384613862261176109314, -366300.36630036626011133193969727]
[ 0, -96153.84615384613862261176109314, -128205.12820512818483014901479085, 96153.84615384613862261176109314, 128205.12820512818483014901479085, 0]
[ -82417.582417582406196743249893188, 0, 82417.582417582406196743249893188, -366300.36630036626011133193969727, 0, 366300.36630036626011133193969727]
Which is obviously very messy. Is there a way I can output it in 4 significant figures in engineering notation, ie for the first entry, 206.0e3?I have tried using the format command, but cannot get it to work, and vpa got me to have it in decimil form, but is very long. Thanks.
0 个评论
回答(2 个)
Steven Lord
2020-11-4
Since vpa worked on this array, it's most likely a symbolic array. If so call vpa with two inputs, the first this array and the second the number of digits you want to use to display the array.
Alternately convert this array (since it contains no symbolic variables) to a double precision array using double then it will respond to the format command.
0 个评论
Michael Croucher
2020-11-3
编辑:Michael Croucher
2020-11-3
There are only a limited number of supported formats that apply automatically to all output. The closest to what you want is shortEng:
format shortEng
Entering
[ 206043.95604395602131262421607971, 0, -206043.95604395602131262421607971, 82417.582417582406196743249893188, 0, -82417.582417582406196743249893188]
will give
ans =
206.0440e+003 0.0000e+000 -206.0440e+003 82.4176e+003 0.0000e+000
but that's not quite what you want because of the precision shown.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!