MATLAB: How to read multiple images at once

image processingImage Processing Toolbox

I need to read 40 .jpeg images from a directory but can't quite figure it out how to do it. I have tried the following code:
A=dir('myDir');
for n=1:length(A)
eval(['M' num2str(n) '=imread(A(n).name);']);
end
I get the following error message when running the code above: Error using imread (line 370) Can't open file "." for reading; you may not have read permission.

Best Answer

Not eval is not used, to make the code much faster and more reliable.
sPath = 'myDir';
sFile = '*.jpg';
sFull = fullfile(sPath,sFile);
S = dir(sFull);
C = cell(size(S));
for k = 1:numel(S)
tmp = fullfile(sPath,S(k).name);
C{k} = imread(tmp);
end
Other comprehensive examples and explanations here:
Related Question