필터 지우기
필터 지우기

Indices of a maximum value in a multidimensional matrix.

조회 수: 31 (최근 30일)
Aftab Ahmed Khan
Aftab Ahmed Khan 2016년 7월 25일
댓글: Aftab Ahmed Khan 2016년 7월 25일
Hi, I have a multidimensional matrix of size (100,16,4,10) and i want to calculate all the 4 indices of the max value in it? Any help please.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 25일
편집: Azzi Abdelmalek 2016년 7월 25일
a=rand(100,16,4,10); %Example
[max_value,idx]=max(a(:))
[x,y,z,w]=ind2sub(size(a),idx)
If the dimension of a is unknown
a=rand(100,16,4,10);
[max_value,idx]=max(a(:))
x=cell(ndims(a),1)
[x{:}]=ind2sub(size(a),idx)
  댓글 수: 3
Thorsten
Thorsten 2016년 7월 25일
use
b = squeeze(a(25,:,:,:));
and compute x, y, z from b; w is 25 by definition.
Aftab Ahmed Khan
Aftab Ahmed Khan 2016년 7월 25일
Thank you. works like a charm.

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

추가 답변 (1개)

Adam
Adam 2016년 7월 25일
편집: Adam 2016년 7월 25일
[maxVal, idx] = max( myMatrix(:) );
[x, y, z, w] = ind2sub( size( myMatrix ), idx );

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by