Q write a function called picker that takes three arguments called condition, in1 and in2 in this order. The argument condition is a logical. If it is true, the function assigns the value of in1 to the output argument out, otherwise, it assigns the v
Show older comments
Q write a function called picker that takes three arguments called condition, in1 and in2 in this order. The argument condition is a logical. If it is true, the function assigns the value of in1 to the output argument out, otherwise, it assigns the value of in2 to out.
Code to call function:
- out=picker(true,1,2)
- out=picker(false,1,2)
4 Comments
VIKASH KUMAR
on 31 Jul 2020
Aditya Vadduri
on 1 Nov 2020
function out=picker(condition, in1, in2)
if(condition==0)
out=in2;
else
out=in1;
end
this works
Abdulsalam ALMABROUK
on 31 May 2021
function out = picker(condition,in1,in2)
if condition == 1;
out = in1;
else
out = in2;
end
Ibad Ur Rahman
on 4 Apr 2022
function out=picker(condition,in1,in2)
if condition==1
out=in1;
else
out=in2;
end
Answers (3)
Chandan Kumar
on 1 Mar 2021
function out = picker(condition,in1,in2)
if (condition==1)
out=in1
else
out=in2
end
Nitin Kapgate
on 5 Aug 2020
0 votes
Hi Vikash,
I understand that you need to write a function (“picker”) which takes three inputs and return one output based on the first argument, which is of logical type.
An answer to a similar question can be found here
VIGNESH B S
on 13 Oct 2021
function ret = picker(condition,in1,in2)
if condition == 1
ret = in1;
else
ret = in2;
end
end
Categories
Find more on Resizing and Reshaping Matrices 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!