Delete rows in a given array based on values in another array

7 Ansichten (letzte 30 Tage)
Hi,
I have two arrays A (179528104x1) and B (1x9700). Here, in the array A, I need to retain only the rows that contain values present in the array B and delete all other rows.

Akzeptierte Antwort

Star Strider
Star Strider am 10 Apr. 2024
Perhaps this —
A = randi(99, 50, 1);
A = 50x1
47 89 42 74 47 16 21 68 21 89
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Abfr = buffer(A,10) % Show Everything In 'A'
Abfr = 10x5
47 55 95 81 17 89 95 38 45 86 42 15 10 33 9 74 86 9 6 58 47 66 17 10 69 16 34 65 7 95 21 88 78 62 93 68 51 56 30 7 21 46 52 86 55 89 68 72 93 94
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
B = randi(99, 10, 1)
B = 10x1
74 38 92 57 99 97 85 55 73 17
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
[ix,v] = ismember(A, B);
C = A(ix)
C = 6x1
74 55 38 17 17 55
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
.

Weitere Antworten (0)

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by