채택된 답변

Jan
Jan 2012년 3월 12일

30 개 추천

X = rand(10, 10);
X(X < 0.1) = NaN;
disp(X);
X(any(isnan(X), 2), :) = [];
Or do you mean exactly one NaN in a row?
X(sum(isnan(X), 2) == 1, :) = [];

댓글 수: 4

chocho
chocho 2017년 3월 7일
how about if one row have Nan(or NA) and another row have NaN (or NA) but in a string like 'GNaNs' or 'GNAs'! i want to delete the row that only have NaN (or NA) and not the row that have NaN(or NA) as string like ('GNaNs' or GNAs'!). i tried isepmty(strfind(str,'NA')) but it delete NA and also GNAs
Jan
Jan 2017년 3월 7일
@chocho phD: I do not understand the question. What does "Nan(or NA)" mean? If you use strfind do you mean cell strings? Then please opena new thread, because it is a different question.
Perhaps you want: strncmp(CStr, 'GNA', 3).
_hi bro in my case i have NA and i want to delete it and keep the Lines which have NA inside
example:
0.255898 NA 0.257966
0.180000 RNASE 0.389999
0.892222 NA 0.458888
0.155523 GNAS 0.892133
*output wanted *
0.180000 RNASE 0.389999
0.155523 GNAS 0.892133
Note: Command i tried is isempty(strfind(l,'NA')) but it delete everything !
Dear chocho phD: Please post some code which creates your input in proper Matlab syntax. It is tedious to guess the type of your data. While "NA" must be a string, the rest of this thread concerned NaN, which is a double number.
Again: Please open a new thread for a new question. Then please post the complete code. "isempty(strfind(l,'NA'))" is only a hint, but we cannot see, where what is deleted by which command.
A bold guess:
C = {0.255898, 'NA', 0.257966; ...
0.180000, 'RNASE', 0.389999; ...
0.892222, 'NA', 0.458888; ...
0.155523, 'GNAS', 0.892133};
Key = C(:,2);
keep = ~cellfun('isempty', strfind(Key, 'NA')) & ~strcmp(Key, 'NA');
Wanted = C(keep, :)
Now this comment has no relation to my answer or to the original question. You cannot vote or accept this solution. So actually Meh's thread has been "highjacked".

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Chris Turnes
Chris Turnes 2017년 3월 7일

5 개 추천

Not that this question needed another answer, but, you can also check out the rmmissing function that was introduced in R2016b. If you combine this with standardizeMissing, you can convert your 'GNAs' strings to a standard missing indicator, and then remove the rows with rmmissing.
carmen
carmen 2012년 3월 12일

1 개 추천

check out the isnan() functioion. the following code looks like a workaround but it works:
A=[1 2 3;nan 4 5;nan 6 nan];
B=A(sum(isnan(A),2)==0);
B %returns the only nan-free row of A: [1 2 3]
hf

댓글 수: 1

A=[1 2 3;nan 4 5;nan 6 nan]
A = 3×3
1 2 3 NaN 4 5 NaN 6 NaN
B=A(sum(isnan(A),2)==0,:);
B %returns the only nan-free row of A: [1 2 3]
B = 1×3
1 2 3

댓글을 달려면 로그인하십시오.

Manuel Aboy
Manuel Aboy 2022년 12월 28일

0 개 추천

mpg = mpg(~ismissing(mpg));

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

질문:

Meh
2012년 3월 12일

답변:

2022년 12월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by