フィルターのクリア

How can I find multiple maximum values and they are indexes of 4-D array

16 ビュー (過去 30 日間)
A
A 2018 年 7 月 16 日
コメント済み: A 2018 年 7 月 17 日
Hi every body, pleas who can help me to find the multiple values and they indexes of 4-D array ?
as an example below :
A(:,:,1,1)=
1 3 5
3 5 1
5 1 3
I want the output as :
max value= 5 , index (3,1,1,1)
max value= 5 , index (2,2,1,1)
max value= 5 , index (1,3,1,1)
My attempt to solve that is :
[max_val, Index] = max(A(:));
[A1,A2,A3,A4] = ind2sub(size(A),Index);
the output was:
max value= 5 , index =3
A1= 3
A2= 1
A3= 1
A4= 1
Which means only the first maximum value, but I want all values. Thank you in advance

採用された回答

Nanditha Nirmal
Nanditha Nirmal 2018 年 7 月 16 日
Hi,
You can try something like this:
maxval = max(A(:));
idx = find(A == maxval);
[A1,A2,A3,A4] = ind2sub(size(A),idx);
This should give all the max value indices.
  1 件のコメント
A
A 2018 年 7 月 17 日
Thanks for your help, it is good solution.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by