Effacer les filtres
Effacer les filtres

how to remove rows from an array containig elements from another array

1 vue (au cours des 30 derniers jours)
DuckDuck
DuckDuck le 19 Nov 2014
Modifié(e) : Guillaume le 19 Nov 2014
Suppose i have a matrix of
a=[1,2;
1,3;
1,4;
2,12;
2,15;
5,7;
5,8;
6,98;
6,99;
7,8;
7,9;
7,11;
9,14;
9,16;
12,18;
14,20;
20,35;
98,102;
99,204;
204,300];
I want to remove rows containing elements from array b, do some manipulations than remove elements of c do smth and than d.
b=[1,2,3,4,12,15,18]
c=[5,7,8,9,14,16,20,35]
d=[6,98,99,102,204,300]
is there a fast and wasy way to do that with built in matlab functions

Réponse acceptée

Guillaume
Guillaume le 19 Nov 2014
Modifié(e) : Guillaume le 19 Nov 2014
Use the negation of ismember to get the elements of a column of a that are not in b. If you want to do that for both columns of a, you have to call ismember twice.
col1notinb = ~ismember(a(:, 1), b);
col2notinb = ~ismember(a(:, 2), b);
awithoutb = a(col1notinb & col2notinb, :);

Plus de réponses (0)

Tags

Aucun tag saisi pour le moment.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by