Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude elements from array [duplicate]

Tags:

vector

matlab

I have a column vector:

A = [1; 2; 3; 4; 4; 5; 5; 7]; 

I wish to exclude the elements of A that are in a second matrix B:

B = [4; 5]

The final result should be:

A = [1; 2; 3; 7]

I am pretty sure using MATLAB elegant syntaxing, this be accomplished without writing a for loop, but not sure how?

like image 855
dr_rk Avatar asked May 29 '13 14:05

dr_rk


1 Answers

I would use Afilt=A(~ismember(A,B));. This will return all elements of A which are not in B.

like image 127
Marc Claesen Avatar answered Sep 28 '22 17:09

Marc Claesen