How to give a condition based on the following situation
1 view (last 30 days)
Show older comments
Pallov Anand
on 27 Apr 2023
Commented: Pallov Anand
on 27 Apr 2023
Suppose there is a condition 'X', and i have two robots R1 and R2. If R1 and R2 both satisfies X, but i want to chose only one of them. How to write a code for this.
Can anyone help.
0 Comments
Accepted Answer
John D'Errico
on 27 Apr 2023
Edited: John D'Errico
on 27 Apr 2023
Why does it matter? Just pick one of them. Or choose randomly between them. Or on odd numbered days, choose the first, on even numbered days, the second. How do you write it? Hard to show you, since you don't say how the test works, or what choosing one of them means.
if R1
% then choose R1
% Do stuff with R1
elseif R2
% choose R2
% Do stuff with R2
else
% Have some coffee, while I wonder what I should do now
end
So if R1 satisfies the condition, then it ALWAYS uses R1. If not, then it checks to see if R2 is an option. If not, then, well, you don't tell us.
The other alternatives are just as easy to write. For example:
if R1
if R2
% Both are an option, so pick randomly
if rand<.5
% Choose R1
else
% choose R2
end
else
% choose R1
end
else
if R2
% choose R2
else
% this is the case where we have no options.
end
end
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB 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!