conditional statement not working correctly
Afficher commentaires plus anciens
I am trying to have my conditional statement check to see if input values that are converted to numbers are within a certain range however whenever it is run it only puts out the else value. Wondering if anyone can help so that it checks the correct ranges
%request for input for lux and heat [F]
Temp = input('Please Enter a Temperature In Farienheit [F]: ',"s");
Lux = input('Please Enter a Value for light [lx]: ',"s");
%convert temp to K
TempK = str2double(Temp) +273;
Lux = str2double(Lux);
%conditionals
if(0>Lux && Lux>100000) && (260>TempK && TempK>310)
error('Both values were not in Range')
elseif (0>Lux) && (Lux>100000)
error('The Lux Value was not between 0-100,000 lx')
elseif (260>TempK) && (TempK>310)
error('The Temperature Value was out of 260-310K range')
else
error('enter values')
end
Réponses (1)
Steven Lord
le 21 Juin 2020
Can you tell me one value for Lux that is simultaneously less than 0 and greater than 100000?
(0>Lux && Lux>100000)
You want to use or (||) instead of and (&&) here and in some or all of your other conditions.
Catégories
En savoir plus sur Choose a Solver dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!