Adding 2 values of old vector into new vector of half size

1 回表示 (過去 30 日間)
Raphael Willi
Raphael Willi 2019 年 11 月 5 日
コメント済み: Raphael Willi 2019 年 11 月 5 日
Suppose you have a vector a = [0; 1; 3; 2; 2; 0; 1; 2]
I am looking for a new vector b, which has half the size of a and stores the sum of two values. Therefore, b will be a summarized version of a, where each value of a is only used once. b should look like this:
b = [1; 5; 2; 3]
Eventually, I would like this to keep going and give me a vector c which does the same with b:
c = [6; 5]
Would this also work with uneven amount of inputs?

採用された回答

Marcel Kreuzberg
Marcel Kreuzberg 2019 年 11 月 5 日
b = a(1:2:end) + a(2:2:end) (this is not working for uneven amount of inputs)

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by