How to sum columns of a matrix in MATLAB in specified number of columns?

1 回表示 (過去 30 日間)
parham kianian
parham kianian 2020 年 1 月 17 日
コメント済み: parham kianian 2020 年 1 月 17 日
I have a matrix A of size 2500*500. I want to sum each 10 columns and get the result as a matrix B of size 2500*50. that is, the first column of matrix B is the sum of first 10 columns of matrix A, the second column of matrix B is the sum of second 10 columns of matrix A and so on. Since I have too many number of matrices like A and I have to do this operation hundreds of times, it is highly time consuming to do that using for loop.
How can I do this without a for loop?

採用された回答

Vladimir Sovkov
Vladimir Sovkov 2020 年 1 月 17 日
B=squeeze( sum( reshape(A,size(A,1),10,[]) ,2) );

その他の回答 (1 件)

KSSV
KSSV 2020 年 1 月 17 日
A = rand(2500,500) ;
B = reshape(A,2500,10,[]) ;
iwant = squeeze(B,2) ;

カテゴリ

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