The numbers do not appear in standard format despite the writing (format shortG)
1 回表示 (過去 30 日間)
古いコメントを表示
format shortG
Mf=6.480554950317725e+03;
Cp_sea=3.976;
t_out=100;
t_in=25;
Qu=Mf*Cp_sea*(t_out-t_in); %useful heat gain (kw)
fprintf('useful heat gain = %dKw\n\n',Qu)
_________
In the previous code, the value of Mf was calculated by an equation and the output was as it appeared despite writing (format shortG) in the first line of the code, and then when adding the (fprintf) command, the output also appears in the long Formula e+3, so how do I overcome this problem
0 件のコメント
回答 (3 件)
Dyuman Joshi
2023 年 3 月 19 日
Using format is only applicable to numeric outputs.
Change the formatting operator in fprintf to obtain the proper value -
format shortG
Mf=6.480554950317725e+03;
Cp_sea=3.976;
t_out=100;
t_in=25;
Qu=Mf*Cp_sea*(t_out-t_in) %useful heat gain (kw)
fprintf('useful heat gain = %g Kw\n\n',Qu)
0 件のコメント
VBBV
2023 年 3 月 19 日
Use %f format specifier
format shortG
Mf=6.480554950317725e+03
Cp_sea=3.976;
t_out=100;
t_in=25;
Qu=Mf*Cp_sea*(t_out-t_in); %useful heat gain (kw)
fprintf('useful heat gain = %.2f kW\n\n',Qu) % use %f
1 件のコメント
VBBV
2023 年 3 月 19 日
Try forcing the computed variable using vpa
format shortG
Mf=6.480554950317725e+03
Cp_sea=3.976;
t_out=100;
t_in=25;
% syms Cp_sea t_out t_in
Qu = vpa(Mf*Cp_sea*(t_out-t_in),8) % somehow
% Qu=vpa(subs(Mf*Cp_sea*(t_out-t_in),{Cp_sea,t_out,t_in},{3.976,100,25}),7) %useful heat gain (kw)
fprintf('useful heat gain = %.2f kW\n\n',Qu) % use %f
Star Strider
2023 年 3 月 19 日
format shortG
Mf=6.480554950317725e+03;
Cp_sea=3.976;
t_out=100;
t_in=25;
Qu=Mf*Cp_sea*(t_out-t_in); %useful heat gain (kw)
fprintf("useful heat gain = " + Qu + " Kw\n\n")
.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!