Find index of a number in a 3d array

조회 수: 9 (최근 30일)
Baiwen Ding
Baiwen Ding 2022년 9월 13일
편집: Bruno Luong 2022년 9월 13일
Hi.
I have a 14610x146x220 3d array. I know that somewhere in this array there is a value of 31.5814 however i dont know what is the index of this value. May i know how do i find out what is the index of this value?
Edit:
For me I used the solution from
Thanks all for helping.

채택된 답변

Torsten
Torsten 2022년 9월 13일
i = find(A(:) == 31.5814);
[i1 i2 i3] = ind2sub([14610,146,220],i(1));
A(i1,i2,i3)
But most probably, floating point inaccuracies will inhit finding the value.
You could try
epsilon = 1e-6;
i = find(abs(A(:)-31.5814)<epsilon);
[i1 i2 i3] = ind2sub([14610,146,220],i(1));
A(i1,i2,i3)
  댓글 수: 6
Baiwen Ding
Baiwen Ding 2022년 9월 13일
Hi thanks for the answer it worked. Do you mind explaining the rationale behind the solution? Thanks.
Bruno Luong
Bruno Luong 2022년 9월 13일
편집: Bruno Luong 2022년 9월 13일
Just look for the closest point to 31.5814, the metric is d=abs(x-31.5814). This solution doesn't need for fine tuning of the tolerance, so easier to work.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by