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

42 次查看(过去 30 天)
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);

采纳的回答

Walter Roberson
Walter Roberson 2021-5-5
编辑:Walter Roberson 2021-10-7
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 个评论
AStro
AStro 2021-10-7
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';

请先登录,再进行评论。

更多回答(1 个)

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

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by