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

16 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Rik
Rik il 19 Set 2019
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 Commenti
Rik
Rik il 19 Set 2019
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 il 19 Set 2019
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)

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by