Submatrix sum (but just on a section)

1 次查看(过去 30 天)
I have a square 4915x4915 matrix (189 countries, 26 sectors for each country and a row and column adjustment). Each country-sector group can be understood as a submatrix. I need to agregate some countries but maintaining the sectoral structure. For example, I need to sum up the elements between 4187:4914 rows and get a 26*4915 submatrix in that space and then repeat the procces for the colums, summing up from column 4187 to column 4914, getting a 4915*26 submatrix in that space, without chainging anythig else in the matrix.
Thanks in advance.
  2 个评论
KSSV
KSSV 2021-6-8
Play with indices. Read about MATLAB array indexing.
Hugo Campos Romero
Thank you. I am actually able to do it, but in a rather "rudimentary" way. I am convinced that there are faster methods than mine, which is to extract the section I am interested in modifying, make the changes, and then reinsert it.

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2021-6-8
编辑:Matt J 2021-6-8
You can use sepblockfun (Download)
A=rand(4914);
B1=sepblockfun(A,[189,1],'sum'); %the results
B2=sepblockfun(A,[1,189],'sum');
whos B*
Name Size Bytes Class Attributes B1 26x4914 1022112 double B2 4914x26 1022112 double

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by