Filter löschen
Filter löschen

Match elements of column array to first column of a matrix then append row of matrix to array

1 Ansicht (letzte 30 Tage)
Hello - I have a column of sets of repeated numbers:
C = [219; 219; 219; 6401; 6401; 6401; 6401; 7501; 7501];
The matrix is like this:
B = [206 3 4 5; 219 4 5 7; 5005 7 5 2; 6401 2 1 8; 7002 1 3 7; 7501 9 4 2};
I want to match a value in the first column of B to the same value in the column A, and then append the remaining rows of B to A.
C = 219 4 5 7
219 4 5 7
219 4 5 7
6401 2 1 8
6401 2 1 8
6401 2 1 8
6401 2 1 8
7501 9 4 2
7501 9 4 2
Thanks!

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 1 Apr. 2014
A = [219
219
219
6401
6401
6401
6401
7501
7501];
B = [206 3 4 5
219 4 5 7
5005 7 5 2
6401 2 1 8
7002 1 3 7
7501 9 4 2];
[l,ii] = ismember(A,B(:,1));
C = B(ii,:);

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB 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