Importing folder of .csv files and saving them as variables with different names.

조회 수: 1 (최근 30일)
BOB
BOB 2014년 5월 14일
편집: Karen DSouza 2018년 7월 17일
I have a folder of 90 .csv files and i want to bring them all into matlab one after the other and save them as vairables and each one have a different name.
Can somebody give me some template code to do this please.
Thanks

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 5월 14일
d='E:\matlab' % your folder
f=dir([d '\*.csv'])
for k=1:numel(f)
data{k}=xlsread(f{k}.name);
end
If you want the data from the third file:
data{3}
Do not use a variable for each file.
  댓글 수: 6
Chugh
Chugh 2018년 5월 23일
Hi, Did you get an answer for your question? I am also searching for the same.
Karen DSouza
Karen DSouza 2018년 7월 17일
편집: Karen DSouza 2018년 7월 17일
What would be the easiest way about horizontally concatenating data tables saved in a cell array like above? I don't want to hard code it because the length of the cell array is subject to change. Essentially from above I have a resulting 1 * 8 cell array with tables of varying # of cols but same amount of rows. I wish to combine all the data from these files by the function join using the column "ID".
Thanks!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by