MATLAB: Sum of cell array Line

arrayscell arraysMATLAB

Hi,
I have a cell array and i need to get the sum of line 4. My cell array is:
A(4,:) =
1×25 cell array
Columns 1 through 8
{0×0 double} {1×45 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
Columns 9 through 16
{0×0 double} {0×0 double} {0×0 double} {1×45 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
Columns 17 through 24
{0×0 double} {1×45 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {1×45 double} {0×0 double}
Column 25
{0×0 double}
The problem is, I need my result in format 1×45 double. I need to add each element individually.
Like this,
If A(4,2) = { 1 2 3 4 5} and A(4, 12) = { 6 7 8 9 10} my result should be: Result = { 3.5 4.5 5.5 6.5 7.5}
how can i do this?
Thanks

Best Answer

% When elements of A are row vectors of the same length
% (like the example in the question)
s = sum(cell2mat(A{4}.'),1);
% When elements of A are column vectors of the same length
s = sum(cell2mat(A{4}),2);