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

1 ビュー (過去 30 日間)
Bryan Tassin
Bryan Tassin 2021 年 8 月 28 日
コメント済み: TADA 2021 年 9 月 5 日
%Code used for first plot
% Need the first plot to look exactly like the second plot
plot(rad1,'red')
hold on
plot(in,'yellow')
plot(in1,'blue')
plot(in2,'green')
title('Position Analysis')
xlabel('\Theta2(rads)')
ylabel('Outputs')
legend({'\Theta3(radians)','R3(in)','R4(in)','R5(in)'},'FontSize',6)
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 件のコメント
Bryan Tassin
Bryan Tassin 2021 年 8 月 28 日
can you be a little more specific? what would i write for this particular situation?

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2021 年 9 月 5 日
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 件のコメント
TADA
TADA 2021 年 9 月 5 日
Image analysts answer is definitely more complete.

サインインしてコメントする。

その他の回答 (1 件)

TADA
TADA 2021 年 8 月 28 日
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;
rad1 = sin(x).^2 .* tan(x);
[localMinValueRad1, localMinIdxRad1] = min(rad1);
[localMaxValueRad1, localMaxIdxRad1] = max(rad1);
plot(rad1, 'red');
hold on;
plot([localMinIdxRad1(:); localMaxIdxRad1(:)], [localMinValueRad1(:); localMaxValueRad1(:)], 'rx');
% continue doing this for the rest of the datasets
  4 件のコメント
TADA
TADA 2021 年 9 月 5 日
what do you mean by changes the plot completely?
did you use my code as-is?

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by