How to sum a specified range of rows in a matrix?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi I'm tryign to sum up sections of a 5000x6482 matrix. I'd like to sum the 1st row with the 17th row, 33rd row and so so on in step sizes of 16 up to 5000. And 2nd row with the 18th row, 34th row etc.
I have tried the code below;
for j = 1:5000
for n = 1:16:6482
test(j,n) = sum(raw_signal(j,n));
end
end
This gives me a 4993x6482 matrix with values in the first row, 17th row, 33rd row... in stepsizes of 16. But the values have just been copied from the orignal matrix without any summation. I think there is more simple solution to this but I can't seem to get it to work. Any help would be much appreciated.
Thanks in advance.
1 comentario
Respuestas (1)
Andrei Bobrov
el 4 de Oct. de 2017
Let A - your array [5000x6482]
d = 16;
ii = rem((0:size(A,1)-1)',d)+1;
[x,y] = ndgrid(ii,1:size(A,2));
out = accumarray([x(:),y(:)],A(:));
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!