How can I find the maximum value and time array in MATLAB?

16 ビュー (過去 30 日間)
Abdulaziz Gheit
Abdulaziz Gheit 2019 年 9 月 19 日
コメント済み: Rik 2019 年 9 月 19 日
Hi
Suppose I have a matrix that has time in column one and other values in column two a = [1 2 ; 4 5 ; 7 8 ; 6 11 ; 4 3 ].
What is the function returning the maximum value in column two and at what time from column one?
For example, the maximum value in the second column of a matrix is 11 and at time equal 6.
Your help would be appreciated
Thanks

回答 (1 件)

Rik
Rik 2019 年 9 月 19 日
Use the second output of max:
a = [1 2 ; 4 5 ; 7 8 ; 6 11 ; 4 3 ];
[val,ind]=max(a(:,2));
time_val=a(ind,1);
  4 件のコメント
Rik
Rik 2019 年 9 月 19 日
Answer posted as comment by Abdulaziz Gheit:
Of course I did. But none of them worked for me. I believe it's more than one function to be used.
I'm a new user to Matlab and I managed to obtain only the indx but not the value itself.
Sure it is simple to be done but not for someone who just starts using Matlab.
Thanks for your attention.
Rik
Rik 2019 年 9 月 19 日
You should probably convert the row-indices to linear indices:
A=rand(4,10);
col_idx=[1 3 6 4];%find with max
row_idx=1:4;%columns searched with max
ind=sub2ind(size(A),row_idx,col_idx);
vals=A(ind)

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by