필터 지우기
필터 지우기

How to format matrix to 4 decimal places in engineering notation:

조회 수: 2 (최근 30일)
Eric Mockapetris
Eric Mockapetris 2020년 11월 3일
답변: Steven Lord 2020년 11월 4일
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.

답변 (2개)

Steven Lord
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.

Michael Croucher
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.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by