Creating a new matrix from unique combinations in two other matrices
1 回表示 (過去 30 日間)
古いコメントを表示
I have two matrices (A & B), each with the same dimensions. Each matrix contains values to divide my data into different bins. How do I create a third matrix (C) of the unique combinations of values in A and B, so that I can then use matrix C to get the mean values of grid points from a different variable at all indices with the same value in C.
I.E., If
A =
1 1 1 2 2 2 3 3 3
1 1 1 2 2 2 3 3 3
1 1 1 2 2 2 3 3 3
B =
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3
then the 3rd matrix (C) would be:
1 1 1 2 2 2 3 3 3
4 4 4 5 5 5 6 6 6
7 7 7 8 8 8 9 9 9
How do I create C? (The actual dataset is much larger than that this)
Thanks!!!
0 件のコメント
採用された回答
Stephen23
2023 年 10 月 23 日
[A,B] = meshgrid(repelem(1:3,3),1:3)
M = [reshape(A.',[],1),reshape(B.',[],1)];
[~,~,X] = unique(M,'rows','stable');
C = reshape(X,flip(size(A))).'
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!