필터 지우기
필터 지우기

How to give a condition based on the following situation

조회 수: 1 (최근 30일)
Pallov Anand
Pallov Anand 2023년 4월 27일
댓글: Pallov Anand 2023년 4월 27일
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에서 Code Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by