How to sum same size cell blocks?

조회 수: 1 (최근 30일)
Xiaohan Du
Xiaohan Du 2016년 12월 21일
답변: John BG 2016년 12월 22일
Hi all,
I have a cell which contains same size matrices, like this:
inpt =
[13x13 double] [13x13 double] [13x13 double] [13x13 double]
Is there a function to sum blocks within a cell? So the result would be a [13*13] matrix with elements of same entry summations of inpt.
Many thanks!

채택된 답변

Guillaume
Guillaume 2016년 12월 21일
sum(cat(3, inpt{:}), 3)
is one way to do it. Basically, concatenate your matrices along an extra dimension and sum along that dimension.

추가 답변 (1개)

John BG
John BG 2016년 12월 22일
Hi Xiaohan
first get the size of inpt
[sz1 sz2]=size(inpt)
and sum the cell2mat version of inpt
sum(reshape(cell2mat(inpt),13,13,sz2),3)
if you find my answer useful would you please mark it as Accepted Answer?
thanks in advance for time and attention
John BG

카테고리

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