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

21 vues (au cours des 30 derniers jours)
Fercho_Sala
Fercho_Sala le 5 Mai 2021
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);

Réponse acceptée

Walter Roberson
Walter Roberson le 5 Mai 2021
Modifié(e) : Walter Roberson le 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 commentaires
AStro
AStro le 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';
Walter Roberson
Walter Roberson le 7 Oct 2021
I think I will need your data to test with

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 5 Mai 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.

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by