Path: news.mathworks.com!not-for-mail
From: "Titus" <titus.edelhofer@mathworks.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: comparison of cell entries
Date: Wed, 8 Aug 2007 14:00:42 +0200
Organization: The MathWorks, Inc.
Lines: 92
Message-ID: <f9cb9f$6rp$1@fred.mathworks.com>
References: <f9cabu$k9r$1@fred.mathworks.com>
NNTP-Posting-Host: de-edelhoft-x.ac.mathworks.de
X-Trace: fred.mathworks.com 1186574448 7033 172.16.75.150 (8 Aug 2007 12:00:48 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 8 Aug 2007 12:00:48 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3028
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
Xref: news.mathworks.com comp.soft-sys.matlab:422935


Hi Corinna,

several comments: line 4 should be a=x{i,9}, to get the element (string), 
because, as the error message tells you, a is a cell array again, if you use 
().
Next: to compare strings, use strcmp instead of ==, and instead of test='' 
use isempty. So we end up with

x=finalTable;
for i=1:(numberOfRows-1)
   a=x{i,9};
   if isempty(a)
       for j=1:9
           x{i,j}=[];
       end
   end
end

Now: instead of marking them, just fill an array with true and false to kill 
those rows later:

x=finalTable;
toBeDeleted = false(numberOfRows,1);
for i=1:(numberOfRows-1)
   a=x{i,9};
   if isempty(a)
    toBeDeleted(i) = true;
   end
end

Why not vectorize? You can do this in one step using cellfun
toBeDeleted = [cellfun(@isempty, x(1:numberOfRows-1,9)); false];

The false at the end, because you don't want to remove the last line?

and now delete the rows:
x(toBeDeleted, :) = [];

Titus




"Corinna Schmitt" <csc@mathworks.com> schrieb im Newsbeitrag 
news:f9cabu$k9r$1@fred.mathworks.com...
> Hallo,
>
> I have a cell construction with 9 columns where the
> following data is stored:
>
> 1   1   1   1   1   AR_WIZ
> 165855.0   59748.0   01_01_01_01
> 1   1   1   1   0   AR_WIZ
> 139876.0   60372.0   01_01_01_01
>             71662.0
>   71760.0
>             71447.0
>   71760.0
>             69771.0
>   70356.0
>
> Now I want to delete those rows where in column 9 nothing
> stands. My idea was the following one:
>
> x=finalTable;
> test='';
> for i=1:(numberOfRows-1)
>    a=x(i,9)
>    if test==a
>        for j=1:9
>            x(i,j)=[];
>        end
>    end
> end
>
> Here an example: If we look in row 1 a=01_01_01_01 so
> nothing is to do. It is the same with row 2. If we now look
> at line 3 a=''. Now the if-cas eis true and all entries in
> x in row 3 should be set to [] which means that the row
> will be deleted.
>
> At the moment I receive the error message: ??? Undefined
> function or method 'eq' for input arguments of type 'cell'.
>
> All in all I want to downsize x in the way that the rows
> where column 9 is empty will be deleted.
>
> Can anyone help me?
>
> Thanks, Corinna