Numerical Differentiation that returns column vector

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.

回答 (1 件)

David Hill
David Hill 2020 年 6 月 17 日

0 投票

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.

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

質問済み:

2020 年 6 月 17 日

回答済み:

2020 年 6 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by