# multiply/divide two cells array

45 views (last 30 days)
shobhit mehrotra on 15 Apr 2015
Commented: Renato Agurto on 15 Apr 2015
I have two cell arrays that have the exact same amount of elements
A: cell 1: [2, 5, 8, 9]
cell 2: [ 5, 7, 3]
cell 3: [ 5, 3]
B: cell 1: [ 1 ,8, 6, 3]
cell 2: [ 4, 2, 7]
cell 3: [ 8, 9]
I want to multiply each element of A by B, (cell 1= [2 40 48 27] ) so I get a new cell array C
I have this
C= cellfun(@x, A(x)*B(x), 'UniformOutput',false)
Thanks!
##### 0 CommentsShow -1 older commentsHide -1 older comments

Sign in to comment.

### Accepted Answer

Renato Agurto on 15 Apr 2015
Hi, you need a 2 input function:
C= cellfun(@(x,y) x*y, A,B, 'UniformOutput',false)
Alternatively:
C = num2cell(cell2mat(A).*cell2mat(B))
I hope this helps
##### 2 CommentsShow 1 older commentHide 1 older comment
Renato Agurto on 15 Apr 2015
You'are right. I though it was a a cell array with single double elements.

Sign in to comment.

### Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!