fprintf returns blank square for value of 1?

4 views (last 30 days)
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!

Accepted Answer

Walter Roberson
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]
DRAT = 1×2
72 105
fprintf('%s bob, your lucky numbers are %g %g\n', DRAT, DRAT)
Hi bob, your lucky numbers are 72 105

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!