Read .txt Files in Looping
Show older comments
I am working in a observation and the data is saved in .txt. I have 111 folders which each of them consists of 816 .txt files and this is how the data looks like.

And this is the script I created to read all files in a folder.
dir_in = 'D:\DATA 1\Materi & Tugas Kuliah\Tugas Akhir\c2\a\c020_out\';
files = dir([dir_in, '\*.txt']);
filename = (files.name);
fid = fopen(filename, 'rt');
c = textscan(fid,'%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s');
lat = c{4};
lon = c{5};
SSH = c{16};
SLA = c{17};
MJD = c{3};
YYF = c{19};
fclose(fid);
But everytime I run the script, the data does not appear. Textscan on variable 'c' reads the first line of the files ONLY, which is the header line, either using 'headerlines' option or not. I guess something wrong goes in that 'fid', but I am not really sure.
I hope someone can help me out. Thank you!
Accepted Answer
More Answers (0)
Categories
Find more on Data Import and Export 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!