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

New to MATLAB?

remove equal items without loop

Asked by huda nawaf

huda nawaf

on 28 Mar 2012
Accepted Answer by Wayne King

Wayne King

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

0 Comments

huda nawaf

huda nawaf

Tags

Products

No products are associated with this question.

2 Answers

Answer by Wayne King

Wayne King

on 28 Mar 2012
Accepted answer
   [~,inx,iny] = intersect(x,y);
   x(inx) = [];
   y(iny) = [];

1 Comment

huda nawaf

huda nawaf

on 28 Mar 2012

many many thanks

Wayne King

Wayne King

Answer by Andrei Bobrov

Andrei Bobrov

on 28 Mar 2012
x = setdiff(x,y)
y = setdiff(y,x)

0 Comments

Andrei Bobrov

Andrei Bobrov

Contact us