How to locate the index of the maximum value in a given range

조회 수: 11 (최근 30일)
FW
FW 2019년 9월 27일
댓글: James Tursa 2019년 9월 27일
Suppose we have two vectors
t= [ 1 2 3 4 5 6 7 8 9 10 11]; % time values
y = [1 2 3 4 5 7 5 4 3 2 1]; % a dependent variable
We can find the max value of y, by max(y), here it is 7. How can we locate the index i of 7 and value the corresponding value of t at idex i? Basically I am trying to locate a peak maximum and its corresponding time.
Thanks

채택된 답변

James Tursa
James Tursa 2019년 9월 27일
편집: James Tursa 2019년 9월 27일
Use the 2nd output of the max function:
[p,i] = max(y);
p is the max value, i is the index of the max value
t(i) is the value of t at the same point as the max of y
  댓글 수: 1
James Tursa
James Tursa 2019년 9월 27일
I don't understand your question. t(i) is the time associated with the max value of y. Isn't that what you wanted?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simultaneous and Synchronized Operations에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by