필터 지우기
필터 지우기

How to find the peaks (both x and y location)

조회 수: 4 (최근 30일)
dj
dj 2014년 10월 12일
댓글: Image Analyst 2014년 10월 13일
Hello.
For instance, if I was plotting Scope (x) and Temperature (y), why can't I use the following code: [pks,locs] = findpeaks(Temperature)?
Matlab tells me that there is 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{:});
It gives me the peaks when I simply use findpeaks(Temperature), but I need the corresponding x values to compute as well.
Could anyone please help me out? Thank you for your time!
  댓글 수: 5
dj
dj 2014년 10월 13일
This is weird. I just reran the code and it works perfectly. It tells me the locations, but does anyone know how could I find the corresponding Scope values with the given locations?
Image Analyst
Image Analyst 2014년 10월 13일
temps = Temperature(locs);
We can't do much more until you attach your code and data files.

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

채택된 답변

Image Analyst
Image Analyst 2014년 10월 12일
Can you run the example in the help without getting any error:
% 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))'))
  댓글 수: 1
dj
dj 2014년 10월 13일
Yes, I can run this fine. Not sure what I'm doing wrong yet ):

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

추가 답변 (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