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!