# How to find location of points used to calculate width of peaks using findpeaks function?

8 visualizzazioni (ultimi 30 giorni)
Lauren il 28 Feb 2016
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 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Sedo il 2 Lug 2020
Bumping this question as of 2020 does anyone know?
dpb il 2 Lug 2020
Dunno' re: R2020; as of R2019b no change...

Accedi per commentare.

### Risposte (2)

Rick Rosson il 29 Feb 2016
Modificato: Rick Rosson il 29 Feb 2016
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
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Mahyar Mehdizadeh il 28 Lug 2020
Thanks! It helped.

Accedi per commentare.

Habib Ali il 21 Giu 2016
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Descriptive Statistics in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by