fprintf is showing NaN
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
i am tryng to create a prgram that gives a prognosis for a temperature reading in any units. the output always offers
The temperature of 36.667 degrees Celsius, results in a prognosis of NaN
why is my message reading NaN, and how can i fix it?
TEMP=input("Temperature in any Units");
UNITS=input("What are the Temperature Units? (Type only the number '1' for Celcius, '2' for farenheiht, or '3' for kelvin)");
if UNITS==1||2||3
if UNITS==1
T=TEMP;
if T<35
PG="Hypothermia";
elseif T>=35&&T<36.111
PG="Possibly Sick";
elseif T>=36.111&&T<37.5
PG="Normal";
elseif T>=37.5&&T<38.333
PG="Fever";
elseif T>=38.333&&T<40
PG="Severe Fever";
elseif T>=40
PG="Hyperplexia";
end
end
if UNITS==2
T=(TEMP-32)*(5/9);
if T<35
PG="Hypothermia";
elseif T>=35&&T<36.111
PG="Possibly Sick";
elseif T>=36.111&&T<37.5
PG="Normal";
elseif T>=37.5&&T<38.333
PG="Fever";
elseif T>=38.333&&T<40
PG="Severe Fever";
elseif T>=40
PG="Hyperplexia";
end
end
if UNITS==3
T=TEMP-273.15;
if T<35
PG="Hypothermia";
elseif T>=35&&T<36.111
PG="Possibly Sick";
elseif T>=36.111&&T<37.5
PG="Normal";
elseif T>=37.5&&T<38.333
PG="Fever";
elseif T>=38.333&&T<40
PG="Severe Fever";
elseif T>=40
PG="Hyperplexia";
end
end
fprintf("The temperature of %.3f degrees Celsius, results in a prognosis of %.3f",T,PG)
end
0 Kommentare
Antworten (1)
Raghav Gnanasambandam
am 5 Feb. 2021
You need to add '%s' for printing a string in fprintf. Here is the corrected code.
TEMP=input("Temperature in any Units");
UNITS=input("What are the Temperature Units? (Type only the number '1' for Celcius, '2' for farenheiht, or '3' for kelvin)");
if UNITS==1||2||3
if UNITS==1
T=TEMP;
if T<35
PG="Hypothermia";
elseif T>=35&&T<36.111
PG="Possibly Sick";
elseif T>=36.111&&T<37.5
PG="Normal";
elseif T>=37.5&&T<38.333
PG="Fever";
elseif T>=38.333&&T<40
PG="Severe Fever";
elseif T>=40
PG="Hyperplexia";
end
end
if UNITS==2
T=(TEMP-32)*(5/9);
if T<35
PG="Hypothermia";
elseif T>=35&&T<36.111
PG="Possibly Sick";
elseif T>=36.111&&T<37.5
PG="Normal";
elseif T>=37.5&&T<38.333
PG="Fever";
elseif T>=38.333&&T<40
PG="Severe Fever";
elseif T>=40
PG="Hyperplexia";
end
end
if UNITS==3
T=TEMP-273.15;
if T<35
PG="Hypothermia";
elseif T>=35&&T<36.111
PG="Possibly Sick";
elseif T>=36.111&&T<37.5
PG="Normal";
elseif T>=37.5&&T<38.333
PG="Fever";
elseif T>=38.333&&T<40
PG="Severe Fever";
elseif T>=40
PG="Hyperplexia";
end
end
fprintf("The temperature of %.3f degrees Celsius, results in a prognosis of %s",T,PG)
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!