How to delete 'NA' columns from a text file?
Show older comments
Hi guys, I have a text file which has 7 rows and 499 columns and in some columns, there are 'NA'
How can i delete them?
Example.txt:
NA T2b t1c t3b
60 79 78 50
7 7 9 7
t2c t3a t2c t3b
4 5 3 NA
0.1 0.1 0.18 0.1
4 4 5 3
2 Comments
Akira Agata
on 3 Apr 2018
You mean, you want to replace 'NA' with some value, such as 0? or you want to delete row or column with 'NA'?
chocho
on 3 Apr 2018
Accepted Answer
More Answers (1)
KSSV
on 3 Apr 2018
fid = fopen('data.txt','rt') ;
S = textscan(fid,'%s','delimiter','\n') ;
fclose(fid) ;
S = S{1} ;
idx = strfind(S, 'NA');
idx = find((cellfun('isempty', idx)));
S = S(idx)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!