## Plot extreme values on a time series

### Isma_gp (view profile)

on 23 Sep 2016
Latest activity Commented on by Fatemah Ebrahim

on 1 Jul 2019

### Star Strider (view profile)

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

### Tags ### Star Strider (view profile)

on 23 Sep 2016

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.

Fatemah Ebrahim

### Fatemah Ebrahim (view profile)

on 1 Jul 2019
How do you show these values (the corresponding time) on the legend?

on 30 Sep 2017
Edited by Payam

### Payam (view profile)

on 30 Sep 2017

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.