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);endPeakSig = 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
Best Answer