MATLAB: Error in reading frames

image processing

i have 140 frames in E drive
path ='E:\surframes\';
files = dir(fullfile(path,'*.jpg'));
I = ((imread(fullfile(path,files(82:118).name))));
i want to read frames 82 to 118,but i get error as
Error using ==> imread at 372
File
"E:\surframes\23.jpg\24.jpg\25.jpg\26.jpg\27.jpg\28.jpg\29.jpg\3.jpg\30.jpg\31.jpg\32.jpg\33.jpg\34.jpg\35.jpg\36.jpg\37.jpg\38.jpg\39.jpg\4.jpg\40.jpg\41.jpg\42.jpg\43.jpg\44.jpg\45.jpg\46.jpg\47.jpg\48.jpg\49.jpg\5.jpg\50.jpg\51.jpg\52.jpg\53.jpg\54.jpg\55.jpg\56.jpg"
does not exist.
Error in ==> final at 26
I = ((imread(fullfile(path,files(82:118).name))));
my frames are ordered from 1 to 140
please help

Best Answer

You're constructing one filename out of lots of them. You're also assuming that the files are listed in order. You need to get the frame number from the file name.
Try this:
I = {};
for f = 1:length(files)
file = files(f).name;
frame = num2str( file(1:find(file,f=='.',1)-1) );
if frame >= 82 && frame <= 118
I{frame} = imread(fullfile(path,file));
end
end
Now you have a cell-array where the elements I{82} through to I{118} will contain your loaded images.