if statement with changing values

2 views (last 30 days)
Joel Schelander
Joel Schelander on 25 Mar 2021
Commented: Stephen23 on 26 Mar 2021
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

Accepted Answer

Stephen23
Stephen23 on 25 Mar 2021
Edited: Stephen23 on 25 Mar 2021
if numel(intersect(ID1,ID2))
  2 Comments
Stephen23
Stephen23 on 26 Mar 2021
Intersect is only defined for two input arrays.

Sign in to comment.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!