Plotting peaks and troughs of a large oscillating simulation data
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Lloyd Sullivan
le 16 Août 2018
Commenté : Star Strider
le 17 Août 2018
Hi there,
I'm trying the create something that looks like this
Based on my data (the top subplot) I've managed to get the peaks (bottom subplot) using the following code
time_tot = d(:,1);
displacement= d(:,2);
[Maxima,MaxIdx] = findpeaks(displacement);
time_max = time_tot([MaxIdx])
i=i+1 ;figure(i)
hold on
subplot(2,1,1)
plot(time_tot,displacement)
subplot(2,1,2)
plot(time_max,Maxima)
hold off
However, I'm not sure how to get the troughs. If anyone could help with this problem, then I would be greatly appreciative.
Best regards,
Lloyd
0 commentaires
Réponse acceptée
Star Strider
le 17 Août 2018
One option, if you are using findpeaks, is to negate it and then plot the negative of the peaks.
Example —
t = linspace(0, 250*pi, 10000); % Create Data
s = sin(t) .* cos(t/50); % Create Data
figure
plot(t, s)
[pospks,posidx] = findpeaks(s); % Positive Peaks
[negpks,negidx] = findpeaks(-s); % Negative Peaks
figure
plot(t(posidx), pospks)
hold on
plot(t(negidx), -negpks)
hold off
2 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!