What is wrong with this easy script
1 view (last 30 days)
Show older comments
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
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
Accepted Answer
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)
More Answers (0)
See Also
Categories
Find more on Digital Filter Analysis 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!