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.
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
> 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
>
I just solved the first error with the following code:
x=finalTable;
test='';
for i=1:(numberOfRows-1)
a=x(i,9);
b=i;
if strcmp(test,a)==1
for j=1:9
x{i,j}=[];
end
end
end
But when I now check the size of x with 'whos' is the same
as before. The wanted rows are not deleted they are just
empty. I now constructed a new variable y:
y=cell(1576,9)
for counter=1:1576
y(counter,1)=x(counter,1);
y(counter,2)=x(counter,2);
y(counter,3)=x(counter,3);
y(counter,4)=x(counter,4);
y(counter,5)=x(counter,5);
y(counter,6)=x(counter,6);
y(counter,7)=x(counter,7);
y(counter,8)=x(counter,8);
y(counter,9)=x(counter,9);
end
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.