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
Sedo
Sedo 2020년 7월 2일
Bumping this question as of 2020 does anyone know?

댓글을 달려면 로그인하십시오.

답변 (2개)

Rick Rosson
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
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.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by