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

1 回表示 (過去 30 日間)
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.

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 2 月 28 日
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

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by