Function error using Input Command
Show older comments
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
Answers (1)
Walter Roberson
on 30 Apr 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.
Categories
Find more on Software Development Tools 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!