0
votes

I'm using MATLAB 2013a and trying to find peak points of my data. When I tried code example given in Find Peaks with Minimum Separation

I am getting the following error:

Error using uddpvparse (line 122)
Invalid Parameter/Value pairs.

Error in findpeaks>parse_inputs (line 84)
hopts = uddpvparse('dspopts.findpeaks',varargin{:});

Error in findpeaks (line 59)
[X,Ph,Pd,Th,Np,Str,infIdx] = parse_inputs(X,varargin{:});

I tried simple x and y vectors and got the same error. What can be the problem?

1

1 Answers

2
votes

I have the same problem as you (R2013a on OSX) with the example by the Mathworks. For some reason it seems we can't use findpeaks with the x-and y-data as input arguments, We need to call the function with the y data and use the [peaks,locations] output to get the peaks/plot them.

It looks like in R2014b they changed some stuff about findpeaks that does not work with older versions...like calling the function with not output argument in R2014b plots the data/peaks without any additional step...but it does not for earlier versions.

Anyhow here is a way to workaround the problem. Call findpeaks with a single input argument (y data that is, you can use property/value pairs as well) and use the indices (locations) to show the peaks:

clc
clear

load sunspot.dat

year = sunspot(:,1);
avSpots = sunspot(:,2);


[peaks, locations] = findpeaks(avSpots)

plot(year,avSpots)

hold on

scatter(year(locations),avSpots(locations),40,'filled')
hold off

Output:

enter image description here

It might be worthwhile to contact The Mathworks about this. Hope that helps!