필터 지우기
필터 지우기

Plot extreme values on a time series

조회 수: 14 (최근 30일)
Isma_gp
Isma_gp 2016년 9월 23일
댓글: Fatemah Ebrahim 2019년 7월 1일
Hi, I have the attached plots. I would like to mark the maximum and minimum value with a marker and show the values on a legend.
Thanks

채택된 답변

Star Strider
Star Strider 2016년 9월 23일
Use the max and min functions with two outputs to get the first instance of the maximum and minimum. Then use the second (index) output to find the value of time where it occurred:
[ymax,maxidx] = max(y);
[ymin,minidx] = min(y);
figure(1)
plot(time, y)
hold on
plot(time(maxidx), ymax, '^r')
plot(time(minidx), ymin, 'vr')
hold off
grid
If you have more than one values for the maximum or minimum, use the find function:
maxidx = find(y == max(y));
and the plot calls then change to:
plot(time(maxidx), y(maxidx), '^r')
and the same for the minima.
NOTE This is UNTESTED CODE but should work.
  댓글 수: 1
Fatemah Ebrahim
Fatemah Ebrahim 2019년 7월 1일
How do you show these values (the corresponding time) on the legend?

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

추가 답변 (1개)

Peppe
Peppe 2017년 9월 30일
편집: Peppe 2017년 9월 30일
Lets say you have a timeserie output where in one column you have Time and in the other you have Data:1 then for finding the max you simply can do
maxPoint = max(x)
It looks through the Data column. Now check for the time idex that is the same as for Data column:
timeIndex = find(x.data == maxPoint);
Now check the time:
x.Time(timeIdex);
Then you plot them as previous comment.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by