Error when using findpeaks for different limits

7 visualizaciones (últimos 30 días)
Joel
Joel el 23 de Abr. de 2023
Editada: Joel el 23 de Abr. de 2023
Hi
I have a script identifying peaks in a curve (EFFEKT). The following part of the script smoothens out the peaks; if there are several peaks close to each other (not going below the limit (Abonnemang) in between), it displays only the biggest.
My limit was initially set to 24200. I want to check the peaks for the limit 23200, 22200, 21200 and 20200.
24200, 23200 and 22200 works fine, but when I set Abonnemang=21200 I get an error after a couple of minutes The plot for 21200 is shown below.
clear all
load EFFEKT
dt = datetime(2021,1,1:1:365);
et = hours(0:23)';
t = repmat(dt,length(et),1) + repmat(et,1,length(dt));
t=t(:);
Abonnemang=21200;
for x=1:numel(EFFEKT)-1 %IF THERE IS SEVERAL PEAKS IN A ROW, TAKE THE BIGGEST
[max_val,locs] = findpeaks(EFFEKT,'MinPeakHeight',Abonnemang,'MinPeakDistance',x); % find the peak and its x axis location
[t0_pos1,s0_pos1,t0_neg1,s0_neg1]= crossing_V7(EFFEKT,t,Abonnemang,'linear'); % positive (pos) and negative (neg) slope crossing points
peak_width = t0_neg1- t0_pos1;
if length(max_val)==length(t0_pos1)
break
end
end
for z=1:length(EFFEKT) %MAKE THE LIMIT A LINE
AB(z)=Abonnemang;
end
figure
plot(t,EFFEKT)
hold on
plot(t,AB)
ylim([-10000 40000])
ylabel('kW')
title('Effektkurva Konsumtion 2021')
Error using findpeaks
Expected MinPeakDistance to be a scalar with value < 8759.
Error in findpeaks>parse_inputs (line 330)
validateattributes(Pd,{'numeric'},{'real','scalar','nonempty','nonnegative','<',x(M)-x(1)},'findpeaks','MinPeakDistance');
Error in findpeaks (line 135)
= parse_inputs(isInMATLAB,Yin,varargin{:});
Error in FLEXfun (line 396)
[max_val,locs] = findpeaks(EFFEKT,'MinPeakHeight',Abonnemang,'MinPeakDistance',x); % find the peak and its x axis location
Error in FINAL (line 24)
[kW,starttid,tid]=FLEXfun(Abonnemang(1),filename{1});

Respuestas (0)

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by