Loop how to sum part of matrix

1 次查看(过去 30 天)
NINA BAJEC
NINA BAJEC 2021-1-19
编辑: NINA BAJEC 2021-1-19
if I have a 9x3 matrix A=[123;123;456;212;121;111;312;141;010] AND i want to get matrix B dimension 3x3 (see photo) so that cell 1,1 would have a sum of 1+2+3 (so in first coulmn of A matrix taking 1,1 cell and 4,1 cell and 7,1 cell) and in the entry of matrix B 2,1 it would be 1+1+1 (taking from matrix A cell 2,1 and 5,1 and 8,1) and in matrix B the entry 3,1 would take from A 4+1+0 so 3,1 cell and 6,1 cell and 9,1 cell and the same logic for column 2 of B and column 3 of B to get at the end B=[647;385;577]
This was just an example in reality I need the same logic for much larger matrix dimension (from 1435x35 getting it into 35x35) so I would be really grateful for loop command or some other help to get the logic of this....

回答(1 个)

Cris LaPierre
Cris LaPierre 2021-1-19
Reshape your matrix to a 3x3x3 and then sum along the 3rd dimension.
  2 个评论
NINA BAJEC
NINA BAJEC 2021-1-19
编辑:NINA BAJEC 2021-1-19
could you please help me with the reshape command and how then to sum every 3rd dimension in a row... I also need to get 3x3 B matrix and this summing over 3rd dimension would give me 3x1 outcome?
Cris LaPierre
Cris LaPierre 2021-1-19
The documentation I linked to contains examples. Take a stab at it yourself first. If you get stuck, share your code and a specific question about what you are not understanding.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by