Numerical Differentiation that returns column vector
조회 수: 4 (최근 30일)
이전 댓글 표시
I am trying to numerically differentiate inside a for loop and return a column vector. In short I have a value theta1inv that is solved inside a for loop and I am trying to find the change with respect to time. The time is 0 to 2 with increments of .005 and I am using that as the for loop condition.
tt=t0:0.005:tf;
for ii=1:length(tt)
Theta1inv has 401 values in a column vector and I am trying to find the change with repect to time. I have used this but it doesn't make a column vector nor does it work in the for loop. But it does give me the correct values from what I can tell.
thetadot1 = gradient(theta1inv(:)) ./ gradient(tt(:));
If I put (ii) after the thetadot1, I get the error code: "Unable to perform assignment because the left and right sides have a different number of elements." It does give me the correct values but not in a column vector and doesn't work in the for loop.
Lastly, theta1inv gives 1x401 double and thetadot gives 401x1 double.
댓글 수: 0
답변 (1개)
David Hill
2020년 6월 17일
If the time interval is constant (.005 between readings), it should be as simple as:
thetadot=diff(theta1inv)/.005;
You will go down to 400x1.
댓글 수: 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!