Filter löschen
Filter löschen

Indices of a maximum value in a multidimensional matrix.

31 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 25 Jul. 2016
Bearbeitet: Azzi Abdelmalek am 25 Jul. 2016
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 Kommentare
Thorsten
Thorsten am 25 Jul. 2016
use
b = squeeze(a(25,:,:,:));
and compute x, y, z from b; w is 25 by definition.
Aftab Ahmed Khan
Aftab Ahmed Khan am 25 Jul. 2016
Thank you. works like a charm.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Adam
Adam am 25 Jul. 2016
Bearbeitet: Adam am 25 Jul. 2016
[maxVal, idx] = max( myMatrix(:) );
[x, y, z, w] = ind2sub( size( myMatrix ), idx );

Kategorien

Mehr zu Language Fundamentals finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by