Using find in a 3d matrix in MATLAB.

조회 수: 219 (최근 30일)
felix
felix 2011년 2월 3일
댓글: Rik 2017년 9월 11일
I have a 3D Matrix such as
QQ=cat(3,w,q)
QQ(:,:,1) =
1 2
3 4
QQ(:,:,2) =
5 6
7 8
now i want to use
[r c]=find(QQ,8) r=max(r) c=max(c)
to find my position for point 8. 'find' just works for 2D arrays .for the 3D case it doesnt work. is there is possibility for 3D arrays?
  댓글 수: 2
felix
felix 2011년 2월 3일
my goal is to get (2,2,2) or r=2, c=2 and v=2 as answer for point 8.thx in front for helping
Kenneth Eaton
Kenneth Eaton 2011년 2월 3일
I think you have a typo in your code. If you're looking for the position of the value 8, you should do FIND(QQ == 8). The second input to FIND isn't the value you're looking for, it's the *number of indices* to find.

댓글을 달려면 로그인하십시오.

채택된 답변

Kenneth Eaton
Kenneth Eaton 2011년 2월 3일
When finding values in multidimensional (i.e. greater than 2-D) arrays using the function FIND, it is best to get a single linear index from FIND then convert it to subscripts using the function IND2SUB. Here's how you can find the position of 8 in your 3-D matrix:
[r,c,v] = ind2sub(size(QQ),find(QQ == 8));
  댓글 수: 2
felix
felix 2011년 2월 3일
thx so much for the fast answer!!=))
Rik
Rik 2017년 9월 11일
I wrote up a function that does this for the general case. It works with the same syntax as the built-in find, but it also supports multidimensional matrices. You can find it on the File Exchange. Then you can simply run:
[r,c,v]=findND(QQ==8);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by