cell arrays to table or normal array in matlab
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Walter Roberson
on 24 Oct 2012
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.
Andrei Bobrov
on 24 Oct 2012
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);
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!