cell arrays to table or normal array in matlab

1 次查看(过去 30 天)
Hi all,
I have cell array show as this:
C =
{1x1 cell} [] []
{1x1 cell} {1x1 cell} []
{1x1 cell} {1x1 cell} {1x1 cell}
{1x1 cell} {1x1 cell} {1x1 cell}
{1x1 cell} {1x1 cell} []
{1x1 cell} {1x1 cell} []
{1x1 cell} {1x1 cell} []
{1x1 cell} {1x1 cell} {1x1 cell}
{1x1 cell} {1x1 cell} []
{1x1 cell} {1x1 cell} []
{1x1 cell} {1x1 cell} {1x1 cell}
{1x1 cell} {1x1 cell} {1x1 cell}
How can I see the contens of a cell array? mena that how can I deal with it like how I deal with normal array? also I want the empty matrix to be shown as zero value in or der to make some processing on it

回答(2 个)

Walter Roberson
Walter Roberson 2012-10-24
For your last part:
C(cellfun(@isempty, C)) = 0;
For your first two parts: as you have cells that contain cell arrays, we cannot determine whether it is possible to reasonably present the contents in a linear form. C{1,1} might be a cell array containing a binary tree, for example.
If the process through which you created C had you expecting something array-like, it could be that you did not create the entries in the best way.
For example,
C{J,K} = [3 5 7];
would be more commonly used than
C{J,K} = {3 5 7};
There are uses for both setups, but the first of these two would probably display more like you expected.
  1 个评论
Jwana
Jwana 2012-10-25
thank you for ur response... for the command : C(cellfun(@isempty, C)) = 0, I have the followng error msg:Conversion to cell from double is not possible !!
I could create 3 vectors from this cells array (which is my target).. but the main problem is that when there is empty cells, it ignore it in a vector term although I need it to be a zero value!! any advice

请先登录,再进行评论。


Andrei Bobrov
Andrei Bobrov 2012-10-24
Your data:
C = arrayfun(@(x){randi(20,randi(5),randi(3))},zeros(10,3),'un',0);
C(randperm(numel(C),5)) = {[]};
% solution
ii = ~cellfun(@isempty,C);
out = cell(size(C));
out(ii) = cellfun(@(x)x{:},C(ii),'un',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