erasing all the rows that begin with NaN

1 回表示 (過去 30 日間)
Sabbas
Sabbas 2012 年 7 月 9 日
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

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 7 月 9 日
just
out = A(~cellfun(@(x)all(isnan(x)),A(:,1)),:)
  1 件のコメント
Sabbas
Sabbas 2012 年 7 月 9 日
it works!thnx

サインインしてコメントする。

その他の回答 (2 件)

Thomas
Thomas 2012 年 7 月 9 日
If A is your input cell matrix
out=cellfun(@isnan,A(:,1),'UniformOutput',false)
count=cellfun(@(x)any(x==1),out);
A(~count,:)
  10 件のコメント
Sabbas
Sabbas 2012 年 7 月 9 日
編集済み: Sabbas 2012 年 7 月 9 日
it works for me when I choose the first two columns. But not when I use the whole matrix
Sabbas
Sabbas 2012 年 7 月 9 日
編集済み: Sabbas 2012 年 7 月 9 日
I used
count=cellfun(@(x)any(x==1),out);
A(count==1,:)=[]
and it seems to work
could you plese verify that the code is equivalent to the one you provided?
thanks

サインインしてコメントする。


Jan
Jan 2012 年 7 月 9 日
編集済み: Jan 2012 年 7 月 9 日
A(cellfun(@(x) isequalwithequalnans(x, NaN), C), :)

カテゴリ

Help Center および File ExchangeData Preprocessing についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by