Borrar filtros
Borrar filtros

3D indices for particular values in a 3D array

1 visualización (últimos 30 días)
William Sherwin
William Sherwin el 8 de Abr. de 2024
Comentada: Stephen23 el 9 de Abr. de 2024
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

Respuesta aceptada

Stephen23
Stephen23 el 8 de Abr. de 2024
Editada: Stephen23 el 8 de Abr. de 2024
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 comentarios
William Sherwin
William Sherwin el 8 de Abr. de 2024
Thanks Stephen23 ! Bill Sherwin
Stephen23
Stephen23 el 9 de Abr. de 2024
@William Sherwin: please remember to click the accept button of the answer that helped you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by