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

Mehri Mehrnia
Mehri Mehrnia 2021년 12월 20일
You can use nnz(matrix), it gives you number of all non-zero elements.

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

 채택된 답변

Jan
Jan 2013년 7월 11일

4 개 추천

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

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 11일
More simple
Jenny
Jenny 2013년 7월 11일
Yes, you are right! Thanks a lot!
Shujaat Khan
Shujaat Khan 2018년 1월 26일
Thanks a lot!
Nicholas Appiah
Nicholas Appiah 2021년 9월 16일
How do you reshape it in the form of the original matrix

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

질문:

2013년 7월 11일

댓글:

2021년 12월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by