vector subtraction

1 次查看(过去 30 天)
Kugen Raj
Kugen Raj 2012-3-16
I have a set of data stored in (kk): kk =
Columns 1 through 8
0 -0.1128 -0.4684 -1.1005 -2.0583 -3.4158 -5.2942 -7.9141
Columns 9 through 16
-11.7597 -18.3555 -56.2068 -19.9206 -15.3116 -13.5578 -13.3223 -14.342
then i used the (diff)command to perform the kk(1)-kk(2) operation. i need to do this until the end: [kk(2)-kk(3)],[kk(3)-kk(4)]..till kk(16).
this is what i get when used the (diff) command:
q =
Columns 1 through 8
-0.1128 -0.3556 -0.6322 -0.9578 -1.3576 -1.8784 -2.6199 -3.8456
Columns 9 through 16
-6.5959 -37.8513 36.2863 4.6090 1.7538 0.2355 -1.0200 -2.4722
for q(1) i suppose to get 0.1128, but im getting a negative value. how can i rectify this problem?

采纳的回答

Sean de Wolski
Sean de Wolski 2012-3-16
Because diff does q(2)-q(1),q(n)-q(n-1).
doc diff
for more info. To correct it, just take the negative.
dqf = -diff(q);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by