How to give a condition based on the following situation

1 vue (au cours des 30 derniers jours)
Pallov Anand
Pallov Anand le 27 Avr 2023
Commenté : Pallov Anand le 27 Avr 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.

Réponse acceptée

John D'Errico
John D'Errico le 27 Avr 2023
Modifié(e) : John D'Errico le 27 Avr 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

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by