MATLAB Answers

# sum of doubles of different cells

1 view (last 30 days)
Mori on 13 Jul 2016
Commented: Mori on 13 Jul 2016
I have two cells (A & B) which each of them has 5*1 cell and each cell 26*1 doubles. How I sum A and B doubles with together into cell C with 5*1 cell and each cell 26*1 doubles.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Elias Gule on 13 Jul 2016
This function should do what you want.
function C = cellsum(A,B)
if iscell(A) && iscell(B)
C = cellfun(@(x,y) cellsum(x,y),A,B,'uniform',false);
else
if isnumeric(A) && isnumeric(B)
C = A + B;
else
C = {}; %%Alternatively, throw an error if you like
end
end
##### 1 CommentShowHide None
Mori on 13 Jul 2016
thank you, working great.

Sign in to comment.

### More Answers (1)

Azzi Abdelmalek on 13 Jul 2016
C=cellfun(@(x,y) x+y,A,B,'un',0)
##### 1 CommentShowHide None
Mori on 13 Jul 2016
cool! faster

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!