I have a for loop that loops over vehicles. I have 2 houses. Each can have one or two cars:
ID1=178 or ID1=[178 180]
ID2=182 or ID2=[178 184}
I want to houses to never have the same vehicle.
I have tried this, but since ID1 and ID2 change size between 1 and 2 for each iteration it won't work. Can I overcome this somehow?
if ID1(1)==ID2(1)
continue
end
if ID1(2)==ID2(1)
continue
end
if ID1(2)==ID2(2)
continue
end

 채택된 답변

Stephen23
Stephen23 2021년 3월 25일
편집: Stephen23 2021년 3월 25일

0 개 추천

if numel(intersect(ID1,ID2))

댓글 수: 2

Joel Schelander
Joel Schelander 2021년 3월 25일
Thanks, I will consider more houses later, does the same apply for:
%Removes all doubles
if numel(intersect(ID1,ID2,ID3))
continue
end
Stephen23
Stephen23 2021년 3월 26일
Intersect is only defined for two input arrays.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품

릴리스

R2019a

질문:

2021년 3월 25일

댓글:

2021년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by