Find non-zero elements in a 3-D matrix

10 visualizaciones (últimos 30 días)
Jenny
Jenny el 11 de Jul. de 2013
Comentada: Mehri Mehrnia el 20 de Dic. de 2021
Hi,
I have a 3-D matrix containing some non-zero numerical values.I want to find the indices of these non-zero elements.
I know find() can give me row and column, but it doesn't work for a 3-D matrix. Is there another function I can use?
  1 comentario
Mehri Mehrnia
Mehri Mehrnia el 20 de Dic. de 2021
You can use nnz(matrix), it gives you number of all non-zero elements.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 11 de Jul. de 2013
Why do you assume, that find() does not work for 3D arrays? Of course it does work. When used with a single output, it replies the linear index. Using this is faster than the 3 separated indices, but you can use ind2sub for a conversion:
ind = find(A);
[i1, i2, i3] = ind2sub(size(A), ind);
  4 comentarios
Shujaat Khan
Shujaat Khan el 26 de En. de 2018
Thanks a lot!
Nicholas Appiah
Nicholas Appiah el 16 de Sept. de 2021
How do you reshape it in the form of the original matrix

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by