Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to delete row of empty cell arrays without reshaping of cell array?

1,145 views
Skip to first unread message

bluesaturn[at]kellnerweg.de

unread,
Feb 26, 2008, 3:32:16 PM2/26/08
to
Hi,
I am able to detect empty cells in a cell array. After deleting these cells the cell itself reshapes.
That's bad.

But I can't figure out how to delete whole rows of empty cells without reshaping of the original cell.

Would be nice if somebody could give me a solution.
I am sorry.

Kind regards,
Gudrun

Walter Roberson

unread,
Feb 26, 2008, 3:53:03 PM2/26/08
to
In article <28303939.1204057966...@nitrogen.mathforum.org>,

bluesaturn[at]kellnerweg.de <blues...@kellnerweg.de> wrote:
>
>I am able to detect empty cells in a cell array. After deleting these cells the cell itself reshapes.
>That's bad.

>But I can't figure out how to delete whole rows of empty cells without reshaping of the original cell.

thecell( all(cellfun(@isempty,thecell),2), : ) = []
--
"MAMA: Oh--So now it's life. Money is life. Once upon a time freedom
used to be life--now it's money. I guess the world really do change.
WALTER: No--it was always money, Mama. We just didn't know about it."
-- Lorraine Hansberry

bluesaturn[at]kellnerweg.de

unread,
Feb 26, 2008, 4:13:47 PM2/26/08
to
Hi Walter,
thank you very much. This much more elegant than what I did.
I figured in the meantime this nasty workaround out:

index=cellfun(@(x) isempty(x),resultdata);
%detect #rows and #columns for reshaping after deleting
sizeresultdata=size(resultdata,1).*size(resultdata,2);
number1=find(index==1);
remainingcells=sizeresultdata-length(number1);
numbercolumns=size(resultdata,2);
numberrows=remainingcells./numbercolumns;

%delete empty cells
resultdata(index)=[];

%reshape cell
resultdata=reshape(resultdata,numberrows,numbercolumns);

How I am supposed to know the all command as a new user? :)
Anyway, thank you very much.
Kind regards.
Gudrun

bluesaturn[at]kellnerweg.de

unread,
Mar 25, 2008, 11:12:33 AM3/25/08
to
Hallo Walter,
instead of a row, I have now empty columns in the middle of my array.
Like that:
5 [] 6
5 [] 6
5 [] 6
5 [] 6

How can I delete the second column in this examples, so that the result will be

5 6
5 6
5 6
5 6

Kind regards,
Gudrun

Jim

unread,
Aug 10, 2008, 11:51:02 PM8/10/08
to
I know this is a bit old but in case others stumble upon
this like me:

array(:,2) = [];

Just make sure to use () instead of {}

"bluesaturn[at]kellnerweg.de" <blues...@kellnerweg.de>
wrote in message
<27550523.1206457983...@nitrogen.mathforum.
org>...

Ben van Oeveren

unread,
Dec 14, 2012, 5:18:06 AM12/14/12
to
Although this is a very old topic. I came across when solving my one problem. Here is my solution.

For cell M = {1,2,3,4;
[],[],[],[];
3,4,5,[]}'

M(:,find(all(cellfun(@isempty,M),1))) = []; %delete whole empty column

M(any(cellfun(@isempty,M),2),:) = []; %delete row with any empty cells


Santosh Puranik

unread,
Aug 4, 2015, 5:24:13 PM8/4/15
to
"bluesaturn[at]kellnerweg.de" <blues...@kellnerweg.de> wrote in message <4859058.12040604580...@nitrogen.mathforum.org>...
I know this is a very old post,But i am stuck in the same situation ,the only difference being that i have first three columns of n rows which have data in them.How do i replace the 'all with the columns to apply this cellfun command.Any help would be appreciated.Thanks
0 new messages