Attach new values to a matrix during loop and then get the integral with cumtrapz command

2 vues (au cours des 30 derniers jours)
Hey there,
a matrix should be initialized and filled with values of time, a signal value and the corresponding integral.
the variable "stepcounter" functions as a control variable to identify when the step threshold is violated. Each step the corresponding integral should be calculated and in the end be added together to finally get a plot of the integral over the time values. However the time values are not steady, hence the thought of the stepcounter. A matrix is defined and should be filled with the right values for the right counter value.
Below you can find the code and I hope you can help me!
i=0;
step = 60;
stepcounter = 1;
for i=2:(length(tay))
if (Integ_MTRX(i, 1)-Integ_MTRX((i-1),1)) > step
stepcounter = stepcounter +1;
Integ_MTRX(i,3) = stepcounter;
else
Integ_MTRX(i,3) = stepcounter;
end
end
for i=1:(stepcounter)
clear temp;
temp = Integ_MTRX(Integ_MTRX(:,3)==i,:);
B(:,i) = temp(:,1);
B(:,i+1) = temp(:,2);
B(:,i+2) = cumtrapz(temp(:,1),temp(:,2));
if stepcounter < 1
B(length(B(:,1))+1:length(B(:,1))+length(temp(:,1)),i) = temp(:,1);
B(length(B(:,2))+1:length(B(:,2))+length(temp(:,2)),i) = temp(:,2);
B(length(B(:,3))+1:length(B(:,3))+length(temp(:,3)),i) = cumtrapz(temp(:,1),temp(:,2));
end
end
  1 commentaire
Shree Charan M L
Shree Charan M L le 11 Oct 2023
It may be useful to share additional code that would help reproducing the error.
From the above code it seems that the condition 'if stepcounter < 1' is never satisfied.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by