Sums from different groupings

2 次查看(过去 30 天)
rpid
rpid 2019-1-28
评论: rpid 2019-1-28
Dear all. I have the table below:
n x1 x2 x3 x4 x5 x6 ...
1 20 9 166 124
2 21 8 80 106
3 23 6 94 105
4 25 7 22 90
5 23 9 166 82
6 21 8 100 72
7 24 8 375 82
8 22 9 350 88
9 25 7 84 105
10 21 5 22 90
11 22 9 59 124
12 26 7 51 106
13 23 6 51 105
...
1118
The x1, x2 and x3 columns are collected data. The x4 is a calculus using the x1 and x2 columns.
I need to sum in 3 to 3, 6 to 6, 9 to 9, 12 to 12, 18 to 18, 24 to 24, 48 to 48... the columns x3 and x4 and rearrange the partial sums in the x5, x6, x8... columns.
Results from x5 and x6 need to be referent to 3 to 3; x7 and x8 to 6 to 6 and so on.
How can I solve this?
Thks!

采纳的回答

Rik
Rik 2019-1-28
You can pad a grouping with NaN values and still use a similar idea as your other question:
x=1:17;
N=3;
if mod(numel(x),N)~=0
x((numel(x)+1):N*ceil(numel(x)/N))=NaN;
end
x
squeeze(sum(reshape(x,3,1,[]),'omitnan'))
  1 个评论
rpid
rpid 2019-1-28
Thank you, it helped me a lot! All groupings tested, problem solved.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by