How to give a condition based on the following situation

1 次查看(过去 30 天)
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.

采纳的回答

John D'Errico
John D'Errico 2023-4-27
编辑:John D'Errico 2023-4-27
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by