How do I import multiple CSV files from a directory as tables in the workspace?
조회 수: 48 (최근 30일)
이전 댓글 표시
Hi!
I have 17 csv files in a directory names as 0000,0001,0002, and so on. I want to import all these csv files as table in the workspace. How can I do that?
Thanks in advance for the help!
댓글 수: 0
답변 (2개)
Arif Hoq
2022년 10월 26일
Try this:
% Get a list of all files in the folder with the desired file name pattern.
myFolder='\\msint82\redirect$\4136\Desktop\a20220729';
filePattern = fullfile(myFolder, '*.csv'); % Change to whatever pattern you need.
fileList = dir(filePattern);
for k = 1 : length(fileList)
% Read in this table.
baseFileName = fileList(k).name;
fullFileName = fullfile(fileList(k).folder, baseFileName);
thisTable = readtable(fullFileName,'VariableNamingRule','preserve');
end
댓글 수: 0
Mathieu NOE
2022년 10월 26일
hello
try this
%% read multiple csv files
P = pwd; % currrent directory
S = dir(fullfile(P,'*.csv')); % get list of files in directory
for k = 1:numel(S)
F = fullfile(S(k).folder, S(k).name);
T{k} = readtable(F); % cell array of tables
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!