cell arrays to table or normal array in matlab
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Walter Roberson
il 24 Ott 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
il 24 Ott 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 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!