フィルターのクリア

Add elements of a vector

7 ビュー (過去 30 日間)
Sofia Melo Vasconcellos
Sofia Melo Vasconcellos 2017 年 3 月 6 日
回答済み: Roger Stafford 2017 年 3 月 7 日
Hello Assuming you have a list of N elements, how to add those elements 10 out of 10, and store the values of each sum in a new vector? I have the impression that using a control structure would help, but I can not see how Thank you!

回答 (2 件)

dpb
dpb 2017 年 3 月 6 日
Not sure what you really mean here, but what about cumsum, maybe???
>> z=1:10;
>> cumsum(z)
ans =
1 3 6 10 15 21 28 36 45 55
>>
If that's the right answer to the wrong question, give an example input and expected output and how it was obtained.

Roger Stafford
Roger Stafford 2017 年 3 月 7 日
Your phrase “add those elements 10 out of 10” is not very specific. I give the solutions to two possible interpretations. Let V be the vector of N elements.
1.) N is a multiple of 10 and you want to take the sum of successive blocks of 10.
Result = sum(reshape(V,10,[]),1);
2.) You want the sum of each successive subsequence V(1:10), V(2:11), V(3:12), V(4:13), ..., V(N-9:N).
Result = sum(hankel(V(1:10),V(10:N)),1);

カテゴリ

Help Center および File ExchangeSimulink Environment Customization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by