3D indices for particular values in a 3D array

1 次查看(过去 30 天)
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>

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by