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

4 Ansichten (letzte 30 Tage)
Abdulaziz Gheit
Abdulaziz Gheit am 19 Sep. 2019
Kommentiert: Rik am 19 Sep. 2019
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

Antworten (1)

Rik
Rik am 19 Sep. 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 Kommentare
Rik
Rik am 19 Sep. 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 am 19 Sep. 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)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by