MATLAB: How to load a excel file in folder

open fileopen folder all csv files

I wrote code which opens a csv file and progress some calculations. Now, I want to open csv files. It is hard to use 'for' loop ,because file names are irregular.
% d=dir('C:\Users\Donghwan\Desktop\mechanical loads');
c=d(3:9); %select csv files
for i=1:length(c)
x=csvread(char(c(i).name));
end

Best Answer

You can run a loop for all the (excel/csv) files in the folder. Go through the below lines of code:
xlfiles = dir('*.csv'); % You are in the folder of csv files/ change extension accordingly
Nfiles = length(xlfiles) ; % number of files
% loop for each file
for i = 1:Nfiles
fname = xlfiles(i).name ; % file name
data = xlsread(fname) ; % read the file
%%do what you want %%%
end