Subtracting the next element on a vector? Basic

8 ビュー (過去 30 日間)
Renato de Sá
Renato de Sá 2011 年 2 月 9 日
コメント済み: Steven Lord 2021 年 1 月 14 日
If I have a vector with n elements, and want a new vector with the subtraction of the first by the second element, and continues...
For exemple: A = [20, 8, 4, 1] turns into B = [(20-8),(8-4),(4,1)]
I started something with
n = length(A);
for k = 1:n
....
but nothing I tried worked them.
Thanks.

採用された回答

Jiro Doke
Jiro Doke 2011 年 2 月 9 日
A = [20, 8, 4, 1];
B = -diff(A);
  2 件のコメント
Renato de Sá
Renato de Sá 2011 年 2 月 9 日
Thank you, sir.
Steven Lord
Steven Lord 2021 年 1 月 14 日
Jayaram ram flagged this as "its working good sir...."
The intended purpose of flags is to alert the editors and/or the admins about spam or other content that's not appropriate for Answers. To comment on the solution please use a comment like I'm doing here. Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by