How to give a condition based on the following situation

1 visualización (últimos 30 días)
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.

Respuesta aceptada

John D'Errico
John D'Errico el 27 de Abr. de 2023
Editada: John D'Errico el 27 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by