# How do I add local min and max values on each line of the plot like the plot shown below?

15 vues (au cours des 30 derniers jours)
Bryan Tassin le 28 Août 2021
Commenté : TADA le 5 Sep 2021
%Code used for first plot
% Need the first plot to look exactly like the second plot
hold on
plot(in,'yellow')
plot(in1,'blue')
plot(in2,'green')
title('Position Analysis')
ylabel('Outputs')
xticks([0 50 100 150 200 250 300 350 400])
xticklabels({'0','\pi/4','\pi/2','3\pi/4','\pi','5\pi/4','3\pi/2','7\pi/4','2\pi'})
##### 2 commentairesAfficher AucuneMasquer Aucune
Ive J le 28 Août 2021
doc annotation
Bryan Tassin le 28 Août 2021
can you be a little more specific? what would i write for this particular situation?

Connectez-vous pour commenter.

### Réponse acceptée

Image Analyst le 5 Sep 2021
If you just have one global peak and valley, try this:
maxValue = max(in);
indexesOfMaxima = find(in == maxValue);
plot(indexesOfMaxima, in(indexesOfMaxima), 'rx', 'LineWidth', 2, 'MarkerSize', 15);
% Repeat for in1 and in2 using their colors.
If you have local mins and maxima, use findpeaks() in the Signal Processing Toolbox
[peakValues, peakIndexes] = findpeaks(in);
[valleyValues, valleyIndexes] = findpeaks(-in); % Turn it upside down then find peaks.
valleyValues = -valleyValues;
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Image analysts answer is definitely more complete.

Connectez-vous pour commenter.

### Plus de réponses (1)

Im not sure, but it seems to me that the plot you are trying to duplicate marks local minima/maxima points as the absolute minimum/maximum values in each dataset, and not using some more complecated peak analysis.
In that case you can easilly find the deeps and peaks using
x = 1:100;
hold on;
% continue doing this for the rest of the datasets
##### 4 commentairesAfficher 2 commentaires plus anciensMasquer 2 commentaires plus anciens
Bryan Tassin le 5 Sep 2021
it changes the plot completely with the code i am running currently. i just need to add markers at the max and min locations on each line.
what do you mean by changes the plot completely?
did you use my code as-is?

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by