cell arrays to table or normal array in matlab

1 Ansicht (letzte 30 Tage)
Jwana
Jwana am 24 Okt. 2012
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

Antworten (2)

Walter Roberson
Walter Roberson am 24 Okt. 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.
  1 Kommentar
Jwana
Jwana am 25 Okt. 2012
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

Melden Sie sich an, um zu kommentieren.


Andrei Bobrov
Andrei Bobrov am 24 Okt. 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);

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by