Consecutive subtraction of the entries of a vector

8 ビュー (過去 30 日間)
Hmm!
Hmm! 2021 年 1 月 13 日
コメント済み: James Tursa 2021 年 1 月 14 日
I am a novist in MATLAB. I have no idea of how to subtract the entries of a vector consecutively. Say if A=[3,5,9,11,15]' and I want something like this B =[3, 2, 4, 2, 4]. Any help will do, thanks in advance.

採用された回答

James Tursa
James Tursa 2021 年 1 月 13 日
編集済み: James Tursa 2021 年 1 月 13 日
If A is a row vector:
B = [A(1) diff(A)];
If A is a column vector:
B = [A(1);diff(A)];
  3 件のコメント
Hmm!
Hmm! 2021 年 1 月 14 日
A typo B = [A(1); A./ A]
James Tursa
James Tursa 2021 年 1 月 14 日
B = [A(1);A(2:end)./A(1:end-1)];

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by