Does findpeaks only provide one output?

6 views (last 30 days)
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

Star Strider
Star Strider on 14 Nov 2022
First, what version /release of MATLAB are you using?
If the version in your documentation (not the online documentation unless your version is R2022b) returns four outputs, the other possibility could be that you have a user function of some sort that is overshadowing the MATLAB findpeaks function. The MATLAB built-in findpeaks function only accepts vectors. The one you cited seems to accept column-oriented matrices.
Run this from a script of the Command Window:
which findpeaks -all
it should only return:
which findpeaks -all
/MATLAB/toolbox/signal/signal/findpeaks.m /MATLAB/toolbox/signal/signal/@dspdata/findpeaks.m % dspdata method /MATLAB/toolbox/signal/signal/@gpuArray/findpeaks.m % gpuArray method
If it returns anything else, that is the problem. The solution is usually to rename the non-MATLAB built-in function, however if you are using a File Exchange contribution that depends on its own ‘findpeaks’ function, renaming it may cause problems with the other functions in that contribution, so you have to be careful.

More Answers (2)

dpb
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...

Image Analyst
Image Analyst on 14 Nov 2022
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:

Community Treasure Hunt

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

Start Hunting!