MATLAB Answers

How can read 30 text data files in matlab ?

4 views (last 30 days)
Salah Djerouni
Salah Djerouni on 28 Feb 2020
Edited: TADA on 2 Mar 2020
I have 30 text data file ,how can read and take from each data text the all value in first column and all data in second column .

  5 Comments

Show 2 older comments
Salah Djerouni
Salah Djerouni on 2 Mar 2020
each file data contain two vectors

Sign in to comment.

Answers (1)

TADA
TADA on 2 Mar 2020
Edited: TADA on 2 Mar 2020
you can alwsay put all of them in a single directory, then use dir to get all file names and iterate through all of them:
path = 'whatever';
files = dir(path);
% get rid of subdirectories and the likes of '.' and '..'
files = files(~[files.isdir])
data = table();
for i = 1:numel(files)
currFile = files(i);
t = readtable(fullfile(path, currFile.name));
findex = ['f', num2str(i)];
data(:, {[findex, '_1st'], [findex, '_2nd']}) = t(:, 1:2);
end

  0 Comments

Sign in to comment.

Products


Release

R2019b

Translated by