Sums from different groupings
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Akzeptierte Antwort
Rik
am 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'))
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!