필터 지우기
필터 지우기

Error in findpeaks when trying to find the x corodinate

조회 수: 3 (최근 30일)
Alexander
Alexander 2014년 12월 15일
댓글: Maximilian Weber 2018년 11월 7일
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
Maximilian Weber
Maximilian Weber 2018년 11월 7일
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,...

댓글을 달려면 로그인하십시오.

채택된 답변

Thorsten
Thorsten 2014년 12월 15일
[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
Alexander
Alexander 2014년 12월 15일
You are amazing. Thank you very much!
Thorsten
Thorsten 2014년 12월 15일
My pleasure :-)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by