Getting dimension indexes based on element index
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
I have a 5D matrix, I found the minimum value and minimum index along the whole elements.
How can I know this minimum belongs to which row, which column, which page. I mean for example if the minimum index is 1108.
How can I know at which row, column and pages, this elmentes locates?
Thanks.
댓글 수: 0
채택된 답변
Karim
2022년 8월 30일
You can use the ind2sub function for this (link --> Convert linear indices to subscripts - MATLAB ind2sub (mathworks.com) )
See below for an example
% random 5D matrix
M = rand(10,10,10,10,10);
% find the minium and its index
[min,idx] = min(M,[],'all')
% convert to subscripts
[I1,I2,I3,I4,I5] = ind2sub(size(M),idx)
추가 답변 (1개)
Chunru
2022년 8월 30일
a = randn(2,3,4,5,6);
[amin, i]=min(a(:))
[i1, i2, i3, i4, i5] = ind2sub([2,3,4,5,6], i)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!