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

1 回表示 (過去 30 日間)
Dennis
Dennis 2022 年 8 月 31 日
コメント済み: Shree Charan M L 2023 年 10 月 11 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by