How to stop displaying scientific notation

27 次查看(过去 30 天)

This calculates a couple different things and I want the answers to be up to 3 decimal places.
prompt = 'Time of flight?(s) ';
t = input(prompt);

if (t <= 45)
h = 15*t.^2;
fprintf('Altitude: %dm\n\n', h)
v = 30*t;
fprintf('Velocity: %dm/s\n\n', v)
if (h <= 11000)
T = (h - 44332.30769230768) / -153.84615384615378;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(-6.5e-3*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(-6.5e-3*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
elseif (h <= 25000)
T = 216.66;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(1*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(1*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
elseif (h <= 47000)
T = (h + 47220) / 333.3;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(3e-3*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(3e-3*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
elseif (h <= 53000)
T = 282.66;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(1*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(1*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
elseif (h <= 79000)
T = (h - 115813) / -222.2;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(-4.5e-3*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(-4.5e-3*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
elseif (h <= 90000)
T = 165.66;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(1*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(1*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
elseif (h <= 110000)
T = (h - 48585) / 250;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(4e-3*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(4e-3*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
end

elseif (t < 117.5)
h = 30375 + (1350*t) + 0.5*(-11.5)*t.^2;
fprintf('Altitude: %dm\n\n', h)
v = 1350 - 11.5*t;
fprintf('Velocity: %dm/s\n\n', v)

if (h <= 11000)
T = (h - 44332.30769230768) / -153.84615384615378;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(-6.5e-3*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(-6.5e-3*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
elseif (h <= 25000)
T = 216.66;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(1*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(1*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
elseif (h <= 47000)
T = (h + 47220) / 333.3;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(3e-3*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(3e-3*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
elseif (h <= 53000)
T = 282.66;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(1*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(1*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
elseif (h <= 79000)
T = (h - 115813) / -222.2;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(-4.5e-3*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(-4.5e-3*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
elseif (h <= 90000)
T = 165.66;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(1*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(1*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
elseif (h <= 110000)
T = (h - 48585) / 250;
fprintf('Temperature: %dk\n\n', T)
P = 101.325*(T/273.15).^(-9.81/(4e-3*287));
fprintf('Pressure: %dkPa\n\n', P)
rho = 1.225*(T/273.15).^-((9.81/(4e-3*287))+1);
fprintf('Density: %dkg/m^3\n\n', rho)
end

end

回答(1 个)

Garv Agarwal
Garv Agarwal 2023-6-26
Hi RetiredCheetoXI,
From my understanding, you want the output data to be in fixed floating-point notation instead of scientific notation. Moreover, it should be up to 3 decimal places.
You can use %f formatting operator instead of %d to achieve this-
fprintf('Temperature: %.3fk\n\n', T)
Where .3 before the f denotes the number of decimal places (in this case three).
For more details, you can refer to the fprintf documentation-

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by