フィルターのクリア

substract an element from previous element in a matrix

2 ビュー (過去 30 日間)
Mahmoud Chawki
Mahmoud Chawki 2022 年 5 月 10 日
コメント済み: Star Strider 2022 年 5 月 10 日
i have a k vector that contains 5 elements.
i want to write a code that substract - the second element from first
- the third element from second
- the fourth element from third
- the fifth element from fourth
and put them all in a vector form that will contain 4 elements
b=[k(2)-k(1) k(3)-k(2) k(4)-k(3) k(5)-k(4)];
how can i do that?

回答 (1 件)

Star Strider
Star Strider 2022 年 5 月 10 日
The diff function seems to be appropriate.
  3 件のコメント
Torsten
Torsten 2022 年 5 月 10 日
b = diff(k.^2)
Star Strider
Star Strider 2022 年 5 月 10 日
@Torsten — Thank you!

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

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by