Find a pair of elements in a 3d matrix
1 回表示 (過去 30 日間)
古いコメントを表示
I have a 512*512*2 matrix. If A is the matrix then I want to find the pair of elements A(:,:,1) and A(:,:,2) that are equal to a specific pair. For example I want to check if the A(1,1,1) and A(1,1,2) are equal to (0,0) and if so to keep the position (1,1). Is there a way to do so?
0 件のコメント
採用された回答
その他の回答 (1 件)
Giovanni Mottola
2016 年 10 月 6 日
Note: if it's 512*512*2 (three dimensional), it's called tensor, not matrix.
A way to do what you require would be to first define the two values you're looking for:
val1=0;
val2=0;
Then call:
[row, col]=find(A(:, :, 1)==val1 & A(:, :, 2)==val2)
Example with a smaller matrix: let
A(:,:,1) =
4 0 5 0 3
1 4 0 0 10
2 5 8 10 3
7 8 4 2 0
7 1 2 10 6
A(:,:,2) =
6 10 2 3 2
9 9 5 5 7
2 7 1 0 10
8 2 9 3 6
3 0 10 5 2
The pair we're looking for is, say, val1=4 and val2=9. Using the command above, we get
row =
2
4
col =
2
3
which can be easily checked.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!