I'm trying to read different files (txt) using a datastore
and readtable
in order to parse them and write them into a .mat
file.
I'm using ds = datastore('*.txt').Files
to get all the file names in a directory, then with a for loop I iterate through all the different files and I save them with different names.
However when I import the file in matlab they have all the same table name (dat
).
Here's the code:
ds = datastore('*.txt');
fnames = ds.Files;
l = length(fnames);
for i = 1:l
dat = readtable(fnames{i}, 'Delimiter', '\t');
dat.Properties.VariableNames(1:2) = {'rpm', 'p_coll'};
dat = removevars(dat{i},20:width(dat));
save([fnames{i} '.mat'],'dat');
end
I tried using an array of dat but it didn't work. Any ideas?