Clear Filters
Clear Filters

Sums from different groupings

2 views (last 30 days)
rpid
rpid on 28 Jan 2019
Commented: rpid on 28 Jan 2019
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!

Accepted Answer

Rik
Rik on 28 Jan 2019
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 Comment
rpid
rpid on 28 Jan 2019
Thank you, it helped me a lot! All groupings tested, problem solved.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!