フィルターのクリア

Which function should I use to find summation of specific values in a column array? I checked already histcounts function but I could not handle it.

1 回表示 (過去 30 日間)
I need to find summation of last 10 terms in a column and continue with this interval until all the intervals are summed values in that column but my another issue is let's say I have 16 rows so last 10 rows are ok but the sum of remained 6 values are also should be calculated and the only difference btw the summation of 10 terms is their range so which functions should I check? I can do it by formulating but I am looking for a shortcut.
  2 件のコメント
Jan
Jan 2022 年 5 月 6 日
編集済み: Jan 2022 年 5 月 6 日
What are your inputs? A vector, matrix multi-dimensional array, time series, table, ...
"I can do it by formulating but I am looking for a shortcut." - How would such a formulation look like for some small example data?
busra gogen
busra gogen 2022 年 5 月 6 日
my inputs may change so this is why I am looking for a function. My input contains years and number of occurence regarding these years. For example, it may be like this:
years #ofevents
1900 5
1901 17
1902 8
1903 9
....
1939 10
This case looks normal because there are 4 intervals but if it ends with 1940, there will be extra one year apart from 10 years intervals.

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

採用された回答

Matt J
Matt J 2022 年 5 月 6 日
編集済み: Matt J 2022 年 5 月 6 日
Let's call your matrix, A. Then,
A=rand(16,2); %hypothetical input
[N,M]=size(A);
N=ceil(N/10)*10;
A(end+1:N,:)=0;
result=sum(reshape(A,10,[]));
result=reshape(result,[],M)
result = 2×2
3.7391 5.6570 3.3933 2.2748
%Check:
sum(A(1:10,:))
ans = 1×2
3.7391 5.6570
sum(A(11:16,:))
ans = 1×2
3.3933 2.2748
  2 件のコメント
busra gogen
busra gogen 2022 年 5 月 6 日
Thank you it works well but I want to obtain the summations by starting from end
busra gogen
busra gogen 2022 年 5 月 6 日
I changed the orientation of column, thank you so much!

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

その他の回答 (0 件)

カテゴリ

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