フィルターのクリア

Adding sequence of data

1 回表示 (過去 30 日間)
Vasu dev
Vasu dev 2021 年 9 月 9 日
コメント済み: Vasu dev 2021 年 9 月 9 日
Hello all, I really need your suggestion to do this code,
I have a vector
a=[1:6]';
I need to add the sequence of elements and store it in another vector.
for i=1:2:5
c=a(i)+a(i+1)
end
a=[1 2 3 4 5 6]';
In 1st iteration : c=1+2
In second Iteration: c=3+4
In third iteration c=5+6
where c stores only one value. I need all the values to be stored in a vector, Ca anyone suggest me a solution
My expected output will be
c=[3 7 11];

採用された回答

Chunru
Chunru 2021 年 9 月 9 日
a=[1 2 3 4 5 6]';
c = sum(reshape(a, 2, []))
c = 1×3
3 7 11
  1 件のコメント
Vasu dev
Vasu dev 2021 年 9 月 9 日
Thank you so much.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Export to MATLAB についてさらに検索

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by