erasing all the rows that begin with NaN
Ältere Kommentare anzeigen
I have a cell matric.
The first two columns of this matrix are
[1x28 char] [ NaN]
[ NaN] [ NaN]
'MART' 'TOTATRIA'
'PREGORY' 'TOSTE'
[ NaN] [ NaN]
My goal is to erase these rows which have as a first element NaN
In the above example I want to erase row2 and the last one
thanks
Akzeptierte Antwort
Weitere Antworten (2)
Thomas
am 9 Jul. 2012
If A is your input cell matrix
out=cellfun(@isnan,A(:,1),'UniformOutput',false)
count=cellfun(@(x)any(x==1),out);
A(~count,:)
10 Kommentare
I'm using your old dataset. What error r u getting? or is it just not working
A = {[ NaN] [ NaN]
[ NaN] [ NaN]
'England' [ NaN]
[ NaN] [ NaN]
' AUSTRIA' ' SMOKES'
'tetete' 'NIKE'
'jhjh khkhkh' 'GOODYS'
' BAND 1' 'HIT'
' BAND 2 KA 1' 'eerrrr'
' BAND 2 KA 2' 'dddddd'
' BAND 2 KA 3' [ NaN]
' BAND 2 KA 4' 'YES' };
out=cellfun(@isnan,A(:,1),'UniformOutput',false)
count=cellfun(@(x)any(x==1),out);
A(~count,:)
Using this works for me.. Removes all rows beginning with NaN's
ans =
'England' [ NaN]
' AUSTRIA' ' SMOKES'
'tetete' 'NIKE'
'jhjh khkhkh' 'GOODYS'
' BAND 1' 'HIT'
' BAND 2 KA 1' 'eerrrr'
' BAND 2 KA 2' 'dddddd'
' BAND 2 KA 3' [ NaN]
' BAND 2 KA 4' 'YES'
Sabbas
am 9 Jul. 2012
Thomas
am 9 Jul. 2012
Using the data you provided in the question
B={ 'Hello' [ NaN]
[ NaN] [ NaN]
'MART' 'TOTATRIA'
'PREGORY' 'TOSTE'
[ NaN] [ NaN]}
A=B;
out=cellfun(@isnan,A(:,1),'UniformOutput',false)
count=cellfun(@(x)any(x==1),out);
A(~count,:)
ans =
'Hello' [ NaN]
'MART' 'TOTATRIA'
'PREGORY' 'TOSTE'
Thomas
am 9 Jul. 2012
Should work irrespective of having numbers or not..
A={ 'Hello' [ NaN]
[ NaN] [ NaN]
[46.65] 'MORE'
'NEW' [46.65]
'MART' 'TOTATRIA'
'PREGORY' 'TOSTE'
[ NaN] [ NaN]};
out=cellfun(@isnan,A(:,1),'UniformOutput',false)
count=cellfun(@(x)any(x==1),out);
A(~count,:)
Jan
am 9 Jul. 2012
@Binish: Is there a difference between "any(x==1)" and "any(x)"?
A(cellfun(@(x) isequalwithequalnans(x, NaN), C), :)
Kategorien
Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!