How to find location of points used to calculate width of peaks using findpeaks function?
10 ビュー (過去 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!