Matlab Live Script Format Problem
15 次查看(过去 30 天)
显示 更早的评论
Hello!
I have a some problem. I want to see the result on shortEng format. But I cant do it.


0 个评论
回答(2 个)
Cris LaPierre
2020-10-30
编辑:Cris LaPierre
2020-10-30
This is likely because your value does not have an exact decimal equivalent. Since the result is symbolic, you are getting the exact representation. If you want to keep the units, use vpa and specify the number of digits to show.
u=symunit;
S_z=2*u.mm;
S_k1=205*u.mm;
N_tvs=231;
S_az=sqrt(3)/2*(S_k1+S_z).^2.*N_tvs;
S_az=unitConvert(S_az,u.m^2);
vpa(S_az,4)
Another option is to convert the symbolic number to double.
[S_az,Unit] = separateUnits(S_az);
S_az = double(S_az)
Walter Roberson
2020-10-30
Symbolic values are never output in shortEng format.
About the closest you will be able to get is
digits(5)
vpa(S_az)
This will give the same number of digits after the decimal place as shortEng would. However, this will not switch to engineering notation until values are at least +/- 1e6, and it will not group by multiples of 3.
I seem to recall that several years ago someone (probably either Jan or Stephen) posted a routine to format non-symbolic numbers in engineering notation. If you had a routine such as that, then you could use it in conjunction with the obscure mapSymType call... (mumble, mumble, mumble...)
In short... it is certainly not easy.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!