Summing matrices of cell arrays

So i have three cell class variables size of 101x5. I need to combine the three of them to form only one cell array of size 101X5. I have tried concatinating the matrices before summing them and I get an error saying "Undefined function 'sum' for input arguments of type 'cell'."How can I get around this?

 채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 14일

0 개 추천

num2cell( sum( cat(3,cell2mat(V1), cell2mat(V2), cell2mat(V3)), 3) )
This depends upon the individual cells holding scalars. If they do not then
cellfun(@(A,B,C) A+B+C, V1, V2, V3, 'Uniform', 0)

댓글 수: 4

Diego Tasso
Diego Tasso 2012년 6월 14일
Thanks ! Mr. Roberson
However, I still get:
Error using cell2mat (line 53)
Cannot support cell arrays containing cell arrays or objects.
[num,data] = xlsread('Connection_List.xlsx','A:E');
[str1] = regexp(data,'304W00','match','ignorecase');
[str2] = regexp(data,'DBC[A-Z]','match','ignorecase');
[str3] = regexp(data,'P01_[A-Z]','match','ignorecase');
this is part of my code....what i want to do is sum str1+str2+str3 where each contains cell arrays 101 X 5
Walter Roberson
Walter Roberson 2012년 6월 14일
You want to sum strings?? What does that mean?
Do you want to sum or do you want to concatenate?
Diego Tasso
Diego Tasso 2012년 6월 14일
I do not want to sum strings....they are just the name the previous coding person used....its just a variable name. I want to sum the cell arrays. I tried concatinating the cells before summing them in another dimension as you suggested above but I got the error I commented previously about cell2mat not supporting cell arrays containig cell arrays. Should I not concatinate before summing?
Diego Tasso
Diego Tasso 2012년 6월 14일
I was tring to sum cell arrays of strings.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by