how to delete NA from specific rows without delete NA included in strings?

what's wrong with this command isempty(strfind(l,'NA')) ??
i have used the code below to delete NA rows but when i execute it i found all NA's rows deleted even NA included in strings such as 'RNASE', 'GNAS'.....
fid = fopen('file1.txt','rt'); %open original file
fid2= fopen('file2.txt','wt'); % open new text file
l= fgetl(fid); %first line
l= fgetl(fid); % the second line
while ~feof(fid)
l=fgetl(fid); %get the next lines
if isempty(strfind(l,'NA'))==0 %remove NA rows
else
idx=regexp(l,'\t','split');
[nrow,ncol]=size(idx); %size of idx (total number of columns in every row)
.........
end
end
input:
  • 0.121213 NA 0.589999
  • 0.421566 RNASE 0.356955
  • 0.11111 GNAS 0.0311120
  • 0.158881 NA 0.0158999
  • 0.122222 SLTP 0.016666
output:
  • 0.122222 SLTP 0.016666
output wanted:
  • 0.421566 RNASE 0.356955
  • 0.11111 GNAS 0.0311120
  • 0.122222 SLTP 0.016666

 Respuesta aceptada

Stephen23
Stephen23 el 8 de Mzo. de 2017
Editada: Stephen23 el 8 de Mzo. de 2017
Try this instead:
if isempty(regexp(l,'\sNA\s','once'))
or perhaps (but less robust):
if isempty(strfind(l,' NA '))
Note also that I removed the unnecessary if- else. Your code currently deletes every row with NA: but you can see that this line also has NA in it:
0.421566 RNASE 0.356955
so it will also get deleted, even though this is not what you want. You want to check for lines that also have space on either side of the NA, like I showed above.

5 comentarios

yes,as you can see ' RNASE', 'GNAS' all have NA but i want to keep them and delete just NA . you can check my input format .
@ *Stephen Cobeldick* , thanks a lot .well done!
exactly what i want.
i see with regexp we can handle so many things! thanks a lot bro and if you have good refernces about regexp and strcmp plz share with us for future use. appreciate your help!...
Thanks @Stephen Cobeldick

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 8 de Mzo. de 2017

Comentada:

el 9 de Mzo. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by