How can I create a matrix based on a double vector lookup?
이전 댓글 표시
I have three vectors of same length:
a=[5;10;10;15;15;15;20;20;20]
b=[3;3;5;3;5;10;3;5;10]
c=[0.2;0.3;-0.1;0.4;0.5;0.6;-0.2;-0.3;0.7]
The entries in a, b and c are related to each other (e.g. first row a=5, b=3 --> c=0.2).
I would like to translate this into a matrix with unique(a) being the row lookup value, unique(b) the column lookup value and "c" the values resulting from the row and column lookup. Making "a" and "b" unique is not a problem but putting this into a matrix with cross-values of "c" seems to be difficult. For all combinations where there is no match, the value should be zero (=0). Final matrix should look like:
[0, 3, 5, 10; ...
5, 0.2, 0, 0;...
10, 0.3, -0.1, 0;...
15, 0.4, 0.5, 0.6;...
20, -0.2, -0.3, 0.7]
Note: The matrix doen't need to have the some row and column dimension. First row and column are the unqiue lookup values from vector "a" and "b"; vector "c" values are in the matrix (2:end,2:end).
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!