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 CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by