Does findpeaks only provide one output?
Show older comments
Hi,
I am trying to use the function findpeaks to extract the magnitude, location and width of peaks in my timeseries data (Find local maxima - MATLAB findpeaks (mathworks.com)).
reading MATLAB's documentation, the function should provide four outputs, and I have found several entries and blog posts that suggest using this function to find all three parameters I need. However if I write it like the documentation suggests (i.e., [pks,locs,w,p] = findpeaks(data1)) I am returned the following error: Error using findpeaks. Too many output arguments.
Indeed, if I look up the function in Matlab the description doesn't match that of the documentation and says this function only returns one output:
help findpeaks
Helper function to find peaks in a given continuous valued time series x
Usage: xmax=chron_findpeaks(data,threshold)
Input:
data (data in time x channels/trials form or a single vector)
threshold (if specified returns locations of peaks at which data exceeds threshold) - optional
Output:
xmax (locations of local maxima of data in a structure array of dimensions channels/trials)
Any help? Am I using the wrong function?
Accepted Answer
More Answers (2)
dpb
on 14 Nov 2022
Moved: Image Analyst
on 14 Nov 2022
You apparently have downloaded either another function or app that has aliased the MathWorks-distributed findpeaks routine. The "helper function" thing gives it away. That's a VERRRY rude thing for anybody to do...
Use
which -all findpeaks
to find the offender; the real one resides in the
>> which -all findpeaks
C:\ML_R2020b\toolbox\signal\signal\findpeaks.m
C:\ML_R2020b\toolbox\signal\signal\@dspdata\findpeaks.m % dspdata method
>>
arena where your install folder will show up in place of "ML_R2020b" here that I use for each release...
1 Comment
sonia turrini
on 14 Nov 2022
Image Analyst
on 14 Nov 2022
0 votes
It can return 4 outputs if you ask for 4. You either are asking for more, or you've redefined findpeaks(). Your m-file is not called findpeaks.m is it? Show you ACTUAL error message -- ALL the red text, not just a snippet of the docuementation followed by a snippet of the error message.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!