how to change the markers and line style, for 'findpeaks' ?

22 views (last 30 days)
Hello, According to the next code, how can I change the ‘markers’ and line style using the ‘findpeaks’ function? Thank you.
[pks,locs,widths,proms] = findpeaks(pws(:,end),y,'MinPeakHeight',trd);
findpeaks(pws(:,end),y,'Annotate','extents','WidthReference','halfprom');
text(locs+0.5,pks,num2str((1:numel(pks))'));
legend('Filtered Data','Peak','Prominence','Width','FontSize',5);

Accepted Answer

Walter Roberson
Walter Roberson on 5 May 2021
Edited: Walter Roberson on 7 Oct 2021
ax = gca;
sig_h = findobj(ax, 'tag', 'Signal');
peak_h = findobj(ax, 'tag', 'Peak');
As you are asking to plot Extents as well, you will also have entries with tag 'Height', 'HalfHeightWidth', 'Border' (multiple); or 'Prominence', 'HalfProminenceWidth', 'Border' (multiple)
You can then set the LineStyle and Marker properties according to your preferences.
  9 Comments
AStro
AStro on 7 Oct 2021
For some reason the Prominence and HalfProminenceWidth tag is not recognized in my code
[pks_wc,locs_wc,widths,proms] = findpeaks(ampl_bgcorr,freq,'MinPeakDistance',p,'MinPeakProminence',10,'Annotate','extents','WidthReference','halfheight');
figure(1)
findpeaks(ampl_bgcorr,freq,'MinPeakDistance',p,'MinPeakProminence',10,'Annotate','extents','WidthReference','halfheight')
ax = gca;
sig_h = findobj(ax, 'tag', 'Signal');
peak_h = findobj(ax, 'tag', 'Peak');
proms_h = findobj(ax, 'tag', 'Prominence');
halfProm_h = findobj(ax, 'tag', 'HalfProminenceWidth');
peak_h.Marker = '.';
peak_h.MarkerSize = 10;
peak_h.Color = 'r';
sig_h.Color = 'b';
proms_h.Color = 'r';
halfProm_h.Color = 'r';
Change of the style of sig_h and peak_h are executed properly but for proms_h I get error message:
Property assignment is not allowed when the object is empty. Use subscripted assignment to create an array element.
Error in CWT_software_v4 (line 142)
proms_h.Color = 'r';

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 5 May 2021
I always plot the results myself:
[peakValues, indexesOfPeaks] = findpeaks(................)
plot(x, y, 'b-', 'LineWidth', 2); % Plot original data.
hold on;
% Extract peak locations from x and y.
xp = x(indexesOfPeaks);
yp = y(indexesOfPeaks);
plot(xp, yp, 'rv', 'LineWidth', 2, 'MarkerSize', 10); % Plot triangles atop the peaks.
Or you could skip creating xp and yp and have for the last line
plot(x(indexesOfPeaks), peakValues, 'rv', 'LineWidth', 2, 'MarkerSize', 10); % Plot triangles atop the peaks.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!