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