Function error using Input Command
Afficher commentaires plus anciens
I am making a function for a class project and I am having trouble finding and fixing the error. When I try to run this function it asks me to input the type of metal I am using but after I type in Al1 for example, it keeps asking me to input the type of metal again. If I type in something other than Al1, nothing happens and it asks for the metal again. How do I fix this?
The function looks like this:
function [k]=ThCond(T)
m=input('What metal are you using?','s');
if m=='Al1'
if (298<=T)&&(T<=840)
k=149.7+0.0809*T-(1*10^-4)*T^2;
end
else fprintf('Please enter a valid temperature.\n');
end
end
Réponses (1)
Walter Roberson
le 30 Avr 2018
0 votes
You should be using strcmp() instead of == to compare character vectors.
That code itself would not prompt a second time for input, but it could be that you are calling the code inside a loop.
Catégories
En savoir plus sur Software Development Tools dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!