I am trying to automate the importing of text file data. How can I call each individual text file name, which is variable, in the readtable function? I have a variable with each textfile name, but am having difficulty using that in the readtable function. Is that a good way to do it? Im not even sure. I attached two text files for examples, any help is appreciated.
textfiles = dir('*.txt');numboffiles = length(textfiles);filelist = {ones(1:numboffiles)};for j =1:numboffiles filelist(j) = {textfiles(j).name}; enddata = ones(length(filelist));for i = 1:length(filelist) fid = fopen(filelist{i}); if fid == -1 fprintf ('Wrong File Name'); else data(i) = readtable(filelist(j), 'Delimiter', '\t', 'ReadVariableNames',false, 'HeaderLines', 9); end end
Best Answer