Array \ Matrix Output display formating

조회 수: 1 (최근 30일)
Roberto Enrique Pinto Villegas
Roberto Enrique Pinto Villegas 2020년 6월 19일
For the next code
syms phi
M=exp(pi*tand(phi))*(tand(45+phi/2))^2;
phi=10:0.5:12;
for i=1:size(phi,2)
N(i)=vpa(subs(M,phi(i)));
end
the output is
[ 10, 2.4714356250900329077526825288117]
[ 21/2, 2.5879028921290203959454380144457]
[ 11, 2.7101851281117024394027253294966]
[ 23/2, 2.8386049798657898988231385226601]
[ 12, 2.973505374766345410079490037392]
how i could change the format to look like?
[ 10, 2.471]
[10.5, 2.587]
...
[ 12, 2.973]
i try
format shortG
but i think calling vpa function don't recive the format style defined before.
Thank you.
  댓글 수: 2
Félix Fernando González Navarro
Just for fun....
clc;
syms phi
M=exp(pi*tand(phi))*(tand(45+phi/2))^2;
phi=10:0.5:12;
for i=1:size(phi,2)
N(i)=subs(M,phi(i));
if mod(phi(i),1)==0
value=sprintf('%4d',phi(i));
else
value=sprintf('%4.1f',phi(i));
end
fprintf('%s,%6.3f\n',value,subs(M,phi(i)));
end
Roberto Enrique Pinto Villegas
Roberto Enrique Pinto Villegas 2020년 6월 19일
Gracias Félix!

댓글을 달려면 로그인하십시오.

채택된 답변

David Hill
David Hill 2020년 6월 19일
You could also round(x, 3) and use format shortG
format shortG;
syms phi
M=exp(pi*tand(phi))*(tand(45+phi/2))^2;
phi=10:0.5:12;
for i=1:size(phi,2)
N(i)=double(vpa(subs(M,phi(i))));
end
  댓글 수: 1
Roberto Enrique Pinto Villegas
Roberto Enrique Pinto Villegas 2020년 6월 19일
This was what i'm looking for... thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by