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

조회 수: 4 (최근 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 CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by