Indices of a maximum value in a multidimensional matrix.

40 ビュー (過去 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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by