How to find location of points used to calculate width of peaks using findpeaks function?
4 次查看(过去 30 天)
显示 更早的评论
In addition to the standard output of findpeaks, I would like to have the corresponding vectors for x1 and x2 (where the horizontal width line intersects the plotted line) that are used to calculate the width (x2-x1). While the location of the peak is given with locs, is there a way to get the two x values used to calculated width for each identified peak?
[pks,locs,widths,proms] = findpeaks(y,x,'Annotate','extents');
4 个评论
回答(2 个)
Rick Rosson
2016-2-29
编辑:Rick Rosson
2016-2-29
Although not ideal, here is a workaround that might help:
ax = gca;
lines = ax.Children;
x = lines(1).XData';
x = x(~isnan(x));
x = transpose(reshape(x,2,[]));
HTH.
Rick
Habib Ali
2016-6-21
Hi, I found a work around to this, which includes manipulating the existing findpeaks.m I copied the findpeaks.m and made a new function findpeaksali.m, you can name it whatever you like. Make sure that this is in your current working directory. So if you call a function [pks,locs,widths,proms] = findpeaksali(y,x,'Annotate','extents'); You might get an error. "Undefined function 'chkinputdatatype' for input arguments of type 'double'." I solved it by copying the script 'chkinputdatatype' from , MATLAB>2015b>toolbox>signal>signal>private to the current directory. Now once I call [pks,locs,widths,proms] = findpeaksali(y,x,'Annotate','extents'); It runs perfectly.
In findpeaksali.m at around line 533, add "disp(wxPk);" and run the code. You will find the x2 and x1 you asked for in the commandline. But they are approximate values. You can work around by rounding them off to the nearest value. You can also modify the output parameters of the function and output wxPk so as to use it in your code. Hope this helps.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!