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

1 次查看(过去 30 天)
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!

采纳的回答

Andrei Bobrov
Andrei Bobrov 2014-4-1
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,:);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by