What is wrong with this easy script

1 view (last 30 days)
in a new script,
Hello,
I am new in Matlab. I am practicing. I don´t know why, Matlab don´t accept this code:
function out=picker(condition,in1,in2)
if condition == 1
out=in1;
elseif condition == 0
out=in2;
end
What is wrong?
Thank you for you time
  2 Comments
David Hill
David Hill on 12 Jul 2020
There is nothing wrong with it. How are you calling it? There is one thing that would simplify and always provide an output.
function out=picker(condition,in1,in2)
if condition %no need for ==1
out=in1;
else %no need for elseif
out=in2;
end
end
% should call function
a = picker(1,1,5) % need three inputs to the function
Joss E.
Joss E. on 12 Jul 2020
I understood it now. For me was very useful, thank you a lot.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 12 Jul 2020
You need to pass in something. You can't just click the green Run triangle without passing in anything for the arguments. For example, you could do this from the command line:
>>out = picker(true, 42, 73)
  1 Comment
Joss E.
Joss E. on 12 Jul 2020
For me was very useful. Thank you a lot for you time. You are very kind. Long life for you

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!