MATLAB: Using dir to locate multiple file names and xslread to load them

dirload multiple filesxlsread

Hello all,
Looking to use dir to load the file names into a structure then use xlsread to load those files.
Code: F=dir('C:\Users\name\Documents\MATLAB\Accel 7\Flex*');
%%That creates a structure with the names of the xls files beginning with 'Flex' in the first field (or column).
%I put them into a cell array just to make it easier
Flexiontrials=struct2cell(F);
Now create a loop to load all of those file names.
for i=1:(length(F)); %%F is equal to 5 in this case
Flexion((length(xlsread(Flexiontrials{i,1}))):5)=xlsread(Flexiontrials{i,1});
end
I receive the following error
Subscripted assignment dimension mismatch.
Error in Class_9_1_16 (line 14) Flexion((length(xlsread(Flexiontrials{i,1}))):i)=xlsread(Flexiontrials{i,1});
Even when I hard code the following I get the same error:
Flexion(1190,5)=xlsread(Flexiontrials{i,1});
Subscripted assignment dimension mismatch.
Error in Class_9_1_16 (line 14) Flexion(1190,5)=xlsread(Flexiontrials{i,1});
I know the dimension size is correct.
Thanks for the help,
CB

Best Answer

Try something like this (untested):
stP = 'C:\Users\name\Documents\MATLAB\Accel 7';
stN = 'Flex*.xls';
S = dir(fullfile(stP,StN));
C = cell(size(S));
for k = 1:numel(S)
name = fullfile(stP,S(k).name);
C{K} = xlsread(name);
end