Adding three cells element wise using cellfun

Folks,
I have three cell arrays of the form 1*6 each containing an 18*9 double. I have attempted to add each corresponding element in each cell array. Ie the ith element of cell A + ith element of cell B + the ith element of cell C.
D = cellfun(@(x,y,z){x+y+z},A{ii},B{ii}, C{ii});
but i get an error stating
??? Error using ==> cellfun Input #2 expected to be a cell array, was double instead.
Any suggestions? B

댓글 수: 2

The ith element of cell A is a 18x9 array, is it right?
A is a 1*6 cell
A{1,1} is an 18*9 double matrix
A{1,2} is an 18*9 double matrix
A{1,n} is an 18*9 double matrix
A{1,6} is an 18*9 double matrix
looking to add the corresponding elements in each matrix.

댓글을 달려면 로그인하십시오.

답변 (3개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 23일
편집: Azzi Abdelmalek 2013년 10월 23일

0 개 추천

n=2;
A{n}+B{n}+C{n}
Is it what you are asking for?
% or maybe you want this
ii=5
out=cellfun(@(x,y,z) x(ii)+y(ii)+z(ii),A,B,C)
Jos (10584)
Jos (10584) 2013년 10월 23일

0 개 추천

D = cell(size(A)) ;
for k=1:numel(A),
D{k} = A{k}+B{k}+C{k} ;
end
bugatti79
bugatti79 2013년 10월 25일

0 개 추천

Hi folks,
Adding the cell arrays of the same dimension works after. Thanks for your help.

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

질문:

2013년 10월 23일

답변:

2013년 10월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by