How to write this logic in MATLAB..?

1 回表示 (過去 30 日間)
harshal j
harshal j 2015 年 12 月 22 日
コメント済み: harshal j 2015 年 12 月 22 日
Hi , I have a column vector of size 1x10 for eg x=[1; 2; 3; 4; 5; 6; 7; 8; 9; 10] i want to perform the addition of first element with the second then second with the third element and so on ( such that new_x=[1;1+2;2+3;3+4;4+5;5+6;6+7;7+8;8+9;9+10]or [first element; first element+second element;second element+third element;....]) i want to know how to write this logic in matlab,i want to do the operation for the vector of size 50010X1

採用された回答

Renato Agurto
Renato Agurto 2015 年 12 月 22 日
new_x = x + [0;x(1:end-1)];
  1 件のコメント
harshal j
harshal j 2015 年 12 月 22 日
Thank u so much for the answer.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 12 月 22 日
new_x = [x(1); x(1:end-1)+x(2:end)];
  1 件のコメント
harshal j
harshal j 2015 年 12 月 22 日
Thank u so much for solving my problem.

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

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by