How to plot the attached waterfall-type diagram and follow the peaks?

조회 수: 4 (최근 30일)
Arash A.
Arash A. 2021년 1월 27일
답변: Abhipsa 2025년 4월 2일
Hi All,
I would be grateful if anyone can help on plotting such a graph and follow the peaks. Any guidance on this matter would be appreciated. Thanks in advance.

답변 (1개)

Abhipsa
Abhipsa 2025년 4월 2일
The findpeaks function in MATLAB can be used to detect and highlight peaks in the curves.
The below code snippet demonstrates the usage of findpeaks
% I am using synthetic data for this demo, you can replace this with your
% actual data
x = linspace(500, 1000, 100);
y1 = 0.1*sin(0.02*x) + 0.05*rand(1,100); % Example noisy sine wave
y2 = 0.12*sin(0.025*x) + 0.03*rand(1,100);
y3 = 0.08*sin(0.03*x) + 0.02*rand(1,100);
% store all curves in a matrix for plotting
Y = [y1; y2; y3];
% definining colors for curves
colors = ['r', 'b', 'g'];
figure;
hold on;
for i = 1:size(Y,1)
% Plot the curves
plot(x, Y(i,:), colors(i), 'LineWidth', 1.5);
% Find peaks
[pks, locs] = findpeaks(Y(i,:), x, 'MinPeakProminence', 0.02);
%pks is a vector with the local minima
% locs is the indices at which the peak occurs
% Plot peaks
scatter(locs, pks, 80, colors(i), 'filled', 'MarkerEdgeColor', 'k');
end
xlabel('X-axis');
ylabel('Y-axis');
title('Peak Detection in Multiple Curves');
legend('Curve 1', 'Peaks 1', 'Curve 2', 'Peaks 2', 'Curve 3', 'Peaks 3');
grid on;
hold off;
You can refer to the below documentation to learn more about findpeaks :
Hope this helps!

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by