Borrar filtros
Borrar filtros

Sums from different groupings

2 visualizaciones (últimos 30 días)
rpid
rpid el 28 de En. de 2019
Comentada: rpid el 28 de En. de 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!

Respuesta aceptada

Rik
Rik el 28 de En. de 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 comentario
rpid
rpid el 28 de En. de 2019
Thank you, it helped me a lot! All groupings tested, problem solved.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by