cell2mat:: Cannot support cell arrays containing cell arrays of strings
조회 수: 1 (최근 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. =)
댓글 수: 0
채택된 답변
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
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);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!