Replacing values for matrices of different dimension
이전 댓글 표시
Suppose,
A= [15 1 4 2 65
15 2 4 6 65
17 6 5 2 65
24 5 3 1 55
24 5 5 3 55
25 2 1 1 55
30 2 1 1 20
31 5 2 2 11
31 5 3 5 11
33 3 2 2 31
33 4 5 3 31
57 3 2 4 2
58 4 5 5 2];
B= [1 1 1
1 1 5
1 1 6
1 2 3
1 3 2
2 1 4
2 1 6
2 2 2
2 2 5
2 3 2
3 1 6
3 2 1
3 2 6
3 3 3
3 3 4
3 3 5
3 4 2
3 4 3
3 4 4
3 4 5
4 1 1
4 2 1
4 2 3
4 2 4
4 2 5
4 3 6
4 6 6
5 1 1
5 1 2
5 1 3
5 1 4
5 1 5
5 4 3
5 5 1
5 6 6
6 1 2
6 1 4
6 1 6
6 2 1
6 2 2
6 2 3];
Both A and B are matrices of different dimensions. I would like to substitute the values in A(:,2:4) with values from B(:,1:3) based on A(column 2).
Resultant (Something like this):
Resultant=[ 15 1 1 1 65
15 2 1 4 65
17 6 1 2 65
24 5 1 1 55
24 5 5 3 55
25 5 1 2 55
30 2 1 6 20
31 5 1 3 11
31 5 1 4 11
33 3 1 6 31
33 4 1 1 31
57 3 2 1 2
58 4 2 1 2];
댓글 수: 2
Walter Roberson
2013년 9월 12일
What is the rule? That when you encounter N in the second column of A, that you do a replacement in columns 2:4 with the first "unused" line in B that has the same value N in the first column? So the first 6 in A(:,2) is matched with the first 6 in B(:,1), the second 6 in A(:,2) is matched with the second 6 in B(:,1) and so on ?
RDG
2013년 9월 12일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!