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

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. =)

 Accepted Answer

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 Comments

Hi!
what I am trying to do is to: ('A'+'B'+'C') like you mentioned above.
So 'A' + 'B' + 'C' should be char(198) since 'A' is char(65), 'B' is char(66), 'C' is char(67) ??
Your strings do not appear to be the same length: should they be extended with blanks to be all the same size, or should they be extended with char(0) ?
I am mystified as to why '304W00' + 'DBCA ' + 'P01_A ' would seem like a good idea ?? That would be [199 162 168 247 145 112] or 'Ç¢¨÷p' and I don't know how you intend to make any sense of that ?? The only variation in the sum would arrive from the [A-Z] of 4th position of the second string, and the [A-Z] of the 5th position of the third string, so why not just calculate something like (V2{J,K}(4) - 'A') * 100 + (V3{J,K}(5) - 'A') thus getting a simple answer such as 2503 for the combination '304W00' 'DBCZ' 'P01_D' ??
Hi Mr. Roberson,
Let me explain it this way:
I have three excel sheets with three columns all the same size. Each column in each sheet has either A, B, C or blank . If I place all three sheets on top of each other all cells will be filled with either A,B or blank and no cells will overlap ( meaning A2 in sheet 1 wont have a value in A2 in sheet 2 already has a value). What I am trying to do is to create this effect. I thought of matrix addition when I arrived at this problem.
Sheet 1................... Sheet 2.............. Sheet 3
Blank Blank A .... B Blank Blank.... Blank C Blank
This creates a sheet that contains cells:
Final Sheet
B C A
Maybe I am overthinking the problem or maybe I am just approaching it all wrong.
Sincere Regards,
Diego
T = ~cellfun(@isempty, Sheet1);
FinalSheet(T) = Sheet1(T);
T = ~cellfun(@isempty, Sheet2);
FinalSheet(T) = Sheet2(T);
T = ~cellfun(@isempty, Sheet3);
FinalSheet(T) = Sheet3(T);
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

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!