cell2mat:: Cannot support cell arrays containing cell arrays of strings

2 次查看(过去 30 天)
Hi!
So I have three cell class variables size of 101x5; each variable apparently contains cell arrays of strings. I need to combine the three of them to form only one cell array of size 101X5. My ultimate goal is to sum them together however I get an error statement:
Undefined function 'sum' for input arguments of type 'cell'
To fix this ( as suggested by Mr. Walter Roberson; thank you by the way ) I need to use the cell2mat function to avoid the error above. So I did that. Now I get the following error:
Cannot support cell arrays containing cell arrays or objects.
Anyone have any ideas how I may reach my ultimate goal? or how I can fix the cell2mat error?
Either way any help is appreciate it. =)

采纳的回答

Walter Roberson
Walter Roberson 2012-6-14
Suppose V1 = {'A'}, V2 = {'B'}, V3 = {'C'} -- the 1x1 simplification of your problem. Now what would it mean for you to "sum" these cell arrays? Would you be trying to get the result 'ABC'? Or would you be trying to get the result char('A' + 'B' + 'C')?
Or would you be wanting the variable named 'A' to be looked up and its numeric value extracted, and the variable named 'B' to be looked up and its numeric value extracted, and likewise for the variable named 'C', and then to sum those three numeric values. If the cell array contains the names of variables whose sum should be taken, then Don't Do That!
  5 个评论
Walter Roberson
Walter Roberson 2012-6-18
T = ~cellfun(@isempty, Sheet1);
FinalSheet(T) = Sheet1(T);
T = ~cellfun(@isempty, Sheet2);
FinalSheet(T) = Sheet2(T);
T = ~cellfun(@isempty, Sheet3);
FinalSheet(T) = Sheet3(T);
Diego Tasso
Diego Tasso 2012-6-18
Thanks. I should learn how to use the cellfun function more. I apologize if I gave you a lot of trouble in trying to understand what I was asking but I appreciate any input from you. Thank you.
Diego

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by