3D indices for particular values in a 3D array

조회 수: 7 (최근 30일)
William Sherwin
William Sherwin 2024년 4월 8일
댓글: Stephen23 2024년 4월 9일
I want to find the 3D indices for particular values in a 3D array. I was expecting to use something like one would use for a 2D array:
>>[row,col] = find(a==8)
So I tried
>>[row,col,page] = find(a==8)
and
>>[row,col,sheet] = find(a==8)
but these just gave nonsense. Surely there is a way to do this?
W.Sherwin@unsw.edu.au

채택된 답변

Stephen23
Stephen23 2024년 4월 8일
편집: Stephen23 2024년 4월 8일
Use IND2SUB:
X = randi(9,4,3,2)
X =
X(:,:,1) = 9 4 1 3 1 8 5 3 7 8 8 4 X(:,:,2) = 7 4 7 7 9 3 6 3 9 8 2 7
[R,C,P] = ind2sub(size(X),find(X==8))
R = 4x1
4 4 2 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
C = 4x1
1 2 3 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
P = 4x1
1 1 1 2
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  댓글 수: 2
William Sherwin
William Sherwin 2024년 4월 8일
Thanks Stephen23 ! Bill Sherwin
Stephen23
Stephen23 2024년 4월 9일
@William Sherwin: please remember to click the accept button of the answer that helped you!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by