Find non-zero elements in a 3-D matrix

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

采纳的回答

Jan
Jan 2013-7-11
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 个评论
Nicholas Appiah
Nicholas Appiah 2021-9-16
How do you reshape it in the form of the original matrix

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by