fprintf returns blank square for value of 1?
4 views (last 30 days)
Show older comments
AH = 0
SLTEMP = 15
SLRHO = 1.225
[DRAT, PRAT, TRAT, RHO, TEMP] = ATM(AH, SLTEMP, SLRHO)
function [DRAT, PRAT, TRAT, RHO, TEMP] = ATM(AH, SLTEMP, SLRHO)
TRAT=(SLTEMP+273.15-6.5*AH/1000.)/(SLTEMP+273.15);
PRAT=TRAT^5.256;
DRAT=TRAT^4.256;
fprintf('Temp ratio = %s\n', TRAT);
fprintf('Pres ratio = %s\n', PRAT);
fprintf('Dens ratio = %s\n', DRAT);
RHO = SLRHO*DRAT;
TEMP = SLTEMP*TRAT;
fprintf('Density = %s kg/m3\n', RHO);
fprintf('Temperature = %s C\n', TEMP);
end
When I set AH to zero, fprintf returns a blank square for TEMP, TRAT, PRAT & DRAT.. however the answer is 1. If i remove the semi colon's I can see that this is the definite answer too.
This is only a problem when AH = zero, as any other value for AH and fprintf shows the correct one. Why is this? thanks!
0 Comments
Accepted Answer
Walter Roberson
on 14 Apr 2021
You are trying to use a %s (string) format to display floating point data. Use a %f or %g format instead.
DRAT = [72 105]
fprintf('%s bob, your lucky numbers are %g %g\n', DRAT, DRAT)
More Answers (0)
See Also
Categories
Find more on Switches and Breakers in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!