How to sum a specified range of rows in a matrix?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Andrei Bobrov
2017 年 10 月 4 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!