Loop how to sum part of matrix
1 次查看(过去 30 天)
显示 更早的评论
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....
0 个评论
回答(1 个)
Cris LaPierre
2021-1-19
2 个评论
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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!