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
0 个评论
回答(2 个)
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.
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);
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!