How to plot the attached waterfall-type diagram and follow the peaks?
3 次查看(过去 30 天)
显示 更早的评论
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.

0 个评论
回答(1 个)
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!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!