Error in findpeaks when trying to find the x corodinate

9 views (last 30 days)
Hello,
I have been testing out the "findpeaks" function and have found that when I use:
[pks,locs] = findpeaks(a),
The Y value of the peaks is correct, but the locs value is just the indices.
Then I use
[pks,locs] = findpeaks(a,t)
I get the following error:
Error using findpeaks>parse_inputs (line 131)
Expected a string for the parameter name, instead the input type was 'double'.
Error in findpeaks (line 71)
[X,Ph,Pd,Th,Np,Str,infIdx] = parse_inputs(Xin,varargin{:});
Error in Damping (line 36)
[pks,locs] = findpeaks(a,t);
I have looked online for some solutions and have found that I get the same error when using this script from this thread: http://www.mathworks.com/matlabcentral/answers/158309-how-to-find-the-peaks-both-x-and-y-location
% Create the sample data
x = linspace(0,1,1000);
Pos = [1 2 3 5 7 8]/10;
Hgt = [4 4 4 2 2 3];
Wdt = [2 6 3 3 4 6]/100;
for n = 1:length(Pos)
Gauss(n,:) = Hgt(n)*exp(-((x - Pos(n))/Wdt(n)).^2);
end
PeakSig = sum(Gauss);
plot(x,Gauss,'--',x,PeakSig)
% Use findpeaks with default settings to find the peaks of the signal and their locations.
[pks,locs] = findpeaks(PeakSig,x)
% Plot the peaks using findpeaks and label them.
findpeaks(PeakSig,x)
text(locs+.02,pks,num2str((1:numel(pks))'))
% Sort the peaks from tallest to shortest.
[psor,lsor] = findpeaks(PeakSig,x,'SortStr','descend');
findpeaks(PeakSig,x)
text(lsor+.02,psor,num2str((1:numel(psor))'))
but I still get the same error:
Error using findpeaks>parse_inputs (line 131)
Expected a string for the parameter name, instead the input type was 'double'.
Error in findpeaks (line 71)
[X,Ph,Pd,Th,Np,Str,infIdx] = parse_inputs(Xin,varargin{:});
Error in Testpeask (line 12)
[pks,locs] = findpeaks(PeakSig,x)
does this mean there is something wrong with my matlab?
Thanks for your help
  1 Comment
Maximilian Weber
Maximilian Weber on 7 Nov 2018
How did you fix this? I'm also stuck with the same error:
Error using findpeaks>parse_inputs (line 288)
Expected a string scalar or character vector for the
parameter name, instead the input type was 'double'.
Error in findpeaks (line 136)
= parse_inputs(isInMATLAB,Yin,varargin{:});
Error in f0est (line 81)
findpeaks(specdb,npartials,'MinPeakWidth',minpeakwidth,'MaxPeakWidth',maxpeakwidth,...

Sign in to comment.

Accepted Answer

Thorsten
Thorsten on 15 Dec 2014
[pks,locs] = findpeaks(PeakSig);
plot(x, PeakSig)
text(x(locs)+.02,pks,num2str((1:numel(pks))'))
Sorted according to height
[pks ind] = sort(pks, 'Descend');
locs = locs(ind);
text(x(locs)+.02,pks,num2str((1:numel(pks))'))
  5 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!