Delete Rows With empty elements

Suppose I have a set of data (a 2x9 matrix):
data2 =
[ 1] [0.0095] [5670000] [936] 'Normal' [0] [0] [0] [ NaN]
[ 2] [0.0095] [5670000] [936] 'Normal' [0] [0] [0] [ NaN]
[ 3] [0.0095] [5670000] [936] 'Normal' [0] [0] [0] [ NaN]
[ 4] [0.0095] [5670000] [936] 'Normal' [0] [0] [0] 'some text'
[ 5] [0.0095] [5670000] [936] 'Normal' [0] [0] [0] 'some text'
I want to be able to detect the NaN's and delete the first three columns.
Typically this is done through
data1(find(sum(isnan(data2),2)==0),:)
but isnan is for input arguements of type 'cell'. What else can I try?

2 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 19 日
Do you want to delete just 3 rows?
T
T 2013 年 8 月 19 日
Yes.

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

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 19 日

1 投票

data1(any(cellfun(@(x) any(isnan(x)),data1),2),:)=[]

3 件のコメント

T
T 2013 年 8 月 19 日
That works but when I try to implement it in a loop, I get an error message when trying to get the index:
data1(any(cellfun(@(x) any(isnan(x)),data1),2),:)=[]
negativeID = [Data2; [{1},{0}]]
a=negativeID(:,1);
find(ismember([a{:}],[Data1{:}])==1)
Data1 ={ 4
5
6
7
8
9
10
11
12
-1
4
5
6
7
8
9
10
11
12
-1
4
5
6
7
8
9
10
11
12
-1
4
5
6
7
8
9
10
11
12
-1}
Data2={[ 4] [0.0119]
[ 5] [0.0119]
[ 6] [0.0143]
[ 7] [0.0143]
[ 8] [0.0187]
[ 9] [0.0256]
[10] [0.0273]
[11] [0.0119]
[12] [0.0143]
[-1] [ 0 ]}
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 19 日
編集済み: Azzi Abdelmalek 2013 年 8 月 19 日
Why have you changed data1? this has nothing to do with your question
T
T 2013 年 8 月 19 日
Sorry, the original post should have read data2.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by