How to import and read multiple .txt files where each .txt file contains multiple number of x,y,z values??

1 visualización (últimos 30 días)
I don't know how to frame my question. I was given initially a .txt file which contains a lot of x,y,z values. I was then assigned each of x, y and z values to the respective variables. Now, I was given a problem where I will be given multiple .txt files which again contains a lot x,y,z values. My task is now to investigate how to import them into matlab and extract date from them efficiently?
I would like to know your suggestions.
Thanks.

Respuestas (1)

Walter Roberson
Walter Roberson el 28 de Feb. de 2021
Or
projectdir = 'name_of_directory'; %can be '.'
dinfo = dir(fullfile(projectdir, '*.txt'));
filenames = fullfile({dinfo.folder}, {dinfo.name});
nfiles = length(filenames);
alldata = cell(nfiles,1);
for K = 1 : nfiles
thisfile = filenames{K};
thisdata = readtable(thisfile);
thisdata.Properties.VariableNames = {'x', 'y', 'z'};
alldata{K} = thisdata;
end
Now alldata will be a cell array of tables, and you can use, for example alldata{7}.x

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by