MATLAB: How to import file names that change in a loop

csv filesimportzeros

I need to import Trial01, Trial02 and so on then Trial10, Triall11 but how do I define the 0 in the first 9 trails from 1 to 9 then not from 10 to 54?
This is my code to import the data:
%% Import data
numfiles = 54; % number of excel files mydata=cell(numfiles,1); % defining size of mydata d=dir('Trial*.csv');
for i=7:length(mydata) % loop to import mutliple excel files
try
mydata{i} = xlsread(d(i).name); % import files into mydata

catch
disp([d(i).name 'read failed'])
end
myfilename = sprintf('Trial%i.csv', i); % define file name
mydata{i} = xlsread(myfilename); % import files into mydata

Best Answer

Change
'Trial%i.csv'
to
'Trial%02d.csv'