フィルターのクリア

adding rows and storing into a matrix

1 回表示 (過去 30 日間)
zozo
zozo 2012 年 1 月 10 日
Hello,
I have a matrix M of size 2880x501 containing 2880 rows. I want to select the first eight rows and all columns [that is, (1:8,:) ], add them and store the resulting row vector(1x501) in a variable 'out'. Then select the next 8 rows, add them and store the resulting row vector(again 1x501) into above variable 'out' and so on....
Finally, I shall have 360 combinations (of 8 rows each) and all these values should be stored in a single variable as
out(360x501)
Please help me achieve this.
  2 件のコメント
Andrei Bobrov
Andrei Bobrov 2012 年 1 月 10 日
out = squeeze(sum(reshape(M.',size(M,2),8,[]),2)).'
zozo
zozo 2012 年 1 月 12 日
thank you @andrei

サインインしてコメントする。

採用された回答

Michael
Michael 2012 年 1 月 10 日
This may be possible without a loop but I don't have the knowledge, however you can loop over i:
for i = 1:360;
out(i,:) = sum(M((i-1)*8+1 : i*8, :));
end
sum automatically operates on the matrix M(1:8,:) and returns the 1x501 vector of sums down the columns.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by