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

matching

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!

Best Answer

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,:);