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?

finding mismatched elements ~ismember

Asked by Lalit Patil

Lalit Patil (view profile)

on 25 Dec 2012
Accepted Answer by Matt J

Matt J (view profile)

 A = [1 2 3;2 3 4;3 4 5;4 5 6;5 6 7;6 7 8;7 8 9]
 B = [2 3 4;6 7 8]
 flag = ~ismember(A,B,'rows');
 index = find(flag);
 q = A(index(flag))

The error is

 ??? Index exceeds matrix dimensions.

and The index finds only first elements of each row. The remaining two should also find it.. So, how to do it.?

2 Comments

Matt J

Matt J (view profile)

on 25 Dec 2012

The index finds only first elements of each row. The remaining two should also find it.

This is not clear. Write explicitly what you want "index" and "q" to be.

Andrei Bobrov

Andrei Bobrov (view profile)

on 25 Dec 2012
q = A(flag,:);

or

q = A(index,:);
Lalit Patil

Lalit Patil (view profile)

Products

No products are associated with this question.

2 Answers

Answer by Matt J

Matt J (view profile)

on 25 Dec 2012
Accepted answer
q = setdiff(A,B,'rows')

0 Comments

Matt J

Matt J (view profile)

Answer by Walter Roberson

Walter Roberson (view profile)

on 25 Dec 2012

Are these integers or numbers with fractions? If they are numbers with fractions then you cannot use ismember() in most cases.

http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

0 Comments

Walter Roberson

Walter Roberson (view profile)

Contact us