Attach new values to a matrix during loop and then get the integral with cumtrapz command
조회 수: 1 (최근 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
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 Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!