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

2 次查看(过去 30 天)
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 个评论
Shree Charan M L
Shree Charan M L 2023-10-11
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by