Comparing arrays and getting the index of extra rows

1 Ansicht (letzte 30 Tage)
Pelajar UM
Pelajar UM am 2 Nov. 2021
Kommentiert: Pelajar UM am 2 Nov. 2021
There are two arrays: A with 8916x3 and B with 6571x3. Each 1x3 set represents xyz coordinates. Array A has some extra coordinates/rows.
I want to compare xyz row by row, and return the index of rows in A that do not exist in B. Then use this index to remove the corresponding extra data from array C (basically C is 8916x3 and it has to be 6571x3 same as B, while keeping the order of rows).
Here's my code but I ge this error: "too many outputs"
[logic,index] =not(ismember(A,B,'rows'))
C(index,:) = [];

Akzeptierte Antwort

DGM
DGM am 2 Nov. 2021
Consider:
% example arrays
B = randi(99,5,3)
B = 5×3
78 21 35 61 79 55 47 76 4 33 86 80 72 26 38
A = [B; randi(99,3,3)];
A = A(randperm(size(A,1)),:)
A = 8×3
78 21 35 61 79 55 10 40 11 55 76 42 50 65 26 72 26 38 47 76 4 33 86 80
% i'm assuming C is some separate array?
C = rand(size(A))
C = 8×3
0.5299 0.1604 0.0717 0.6433 0.3189 0.3384 0.6323 0.7470 0.2365 0.1172 0.1725 0.8113 0.3856 0.8772 0.6111 0.0621 0.1053 0.8808 0.9019 0.1290 0.7942 0.0757 0.7127 0.5547
% extract rows from C where A is a member of B, preserving order
C = C(ismember(A,B,'rows'),:)
C = 5×3
0.5299 0.1604 0.0717 0.6433 0.3189 0.3384 0.0621 0.1053 0.8808 0.9019 0.1290 0.7942 0.0757 0.7127 0.5547

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by