Azzera filtri
Azzera filtri

Find and remove data from array that does not match 2nd array

9 visualizzazioni (ultimi 30 giorni)
I have two arrays. Array A has data which I would like to mimimize based on the contents of array B.
For example, Array A is:
[3, 10, 100;
5, 20, 200;
7, 30, 300;
5, 40, 400;
6, 50 500]
Array B is
[6; 7]
I would like to keep only the rows of array A, which match ANY of the contents of array B:
i.e. in Column 1 of Array A, row 3 and row 5 have values which match contents in Array B (6 & 7).
Note: numbers are random, and wil not be in order
So the final result would like to be:
[7, 30, 300;
6, 50 500]

Risposta accettata

Image Analyst
Image Analyst il 14 Dic 2020
Use ismember():
A = [3, 10, 100;
5, 20, 200;
7, 30, 300;
5, 40, 400;
6, 50 500]
B = [6; 7]
[ia, ib] = ismember(B, A)
C = A(ib,:)

Più risposte (0)

Categorie

Scopri di più su Cell Arrays in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by