MATLAB Answers

huda nawaf

remove equal items without loop

Asked by huda nawaf
on 28 Mar 2012

hi, I want to remove any two item are equal without loop x=[1 2 3 5]; y=[4 3 1 6 7]; I want the result be x=[2 5] y=[4 6 7] how do that? thanks




No products are associated with this question.

2 Answers

Answer by Wayne King
on 28 Mar 2012
 Accepted answer

   [~,inx,iny] = intersect(x,y);
   x(inx) = [];
   y(iny) = [];

  1 Comment

many many thanks

Answer by Andrei Bobrov
on 28 Mar 2012

x = setdiff(x,y)
y = setdiff(y,x)


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!