Read multiple csv files from a folder and not all csv files

1 view (last 30 days)
I want to read multiple csv files from a folder and not all csv files.I have the names of the particular csv files in notepad format and i want to import those particular
files in matlab by reading that notepad files.
Eg loads.csv
loads1.csv
loads2.csv
loads3.csv
Suppose i want to read only loads.csv and loads2.csv from a folder
Currently am copying and pasting and creating a new folder and using function
f=dir(fullfile('D:\Matlab,'*.csv'));
But if i want to reduce the time and directly read the names from the notepad and go and search for those particular files in that folder so how to do it?

Answers (1)

KSSV
KSSV on 10 Jan 2019
Edited: KSSV on 10 Jan 2019
fid = fopen('myfile.txt','rt') ; % open your text pad file
S = textscan(fid,'%s','delimiter','\n') ;
S = S{1} ; % this has file names which are in notepad file
fclose(fid) ; % close the file
N = length(S) ; % toal number of files
% loop for ewach file
for i = 1:N
[num,txt,raw] = xlsread(S{i}) ; % read file, also use look into csvread
end

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!