vector subtraction

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 日

0 投票

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 件)

カテゴリ

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

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by