Add data from one matrix to another by the values of one column
이전 댓글 표시
I have two matrix of different sizes and they both have two columns, one with ID of the data and other with the data i want. Is there any way to add data with the same ID number from the first column in a third column without using a loop?
The matrix are both cell arrays like these:
1000 [10370;10371;10372] 1002 52
1001 [12933;12934] 2000 60
1002 10001 1000 42
2000 11320 2003 57
2001 [11347;11348]
2002 [10362;10363]
2003 [12632;12633]
And the desired result would be something like this
1000 [10370;10371;10372] 42
1001 [12933;12934]
1002 10001 52
2000 11320 60
2001 [11347;11348]
2002 [10362;10363]
2003 [12632;12633] 57
채택된 답변
추가 답변 (1개)
C1 = {
1000 [10370;10371;10372]
1001 [12933;12934]
1002 10001
2000 11320
2001 [11347;11348]
2002 [10362;10363]
2003 [12632;12633]};
C2 = {1002 52
2000 60
1000 42
2003 57};
[tf,loc] = ismember([C2{:,1}]',[C1{:,1}]');
C3 =[C1, cell(height(C1),1)];
C3(loc,3) = C2(:,2)
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!