making a function that uses a string input
Show older comments
I am trying to make a function:
function [y]=my_function(A,B,C)
where A is a string and B and C are just numbers. If someone enters 'yes' for A then a number for B and C I want it to do one calculation. If someone enters 'no' for A then numbers for B and C I want it to do another calculation. I was trying to use if statements i.e.
if A='yes'
calculations
end
if A='no'
calculations
end
but I can't get the function to accept strings and then use them with the if statements. Is there a way to do this or am I way off? Thanks. Let me know if I wasn't clear with something.
Accepted Answer
More Answers (1)
Jun
on 20 Oct 2011
4 votes
You can try strcmp or strcmpi
for example, if strcmp(A,'yes')...
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!