Try?
%Save the folder of images in the current directory
path_directory='Test3'; % 'Folder name'
original_files=dir([path_directory '/*.jpg']);
filename=[path_directory '/' original_files(random(length(original_files))).name];
image_data=imread(filename);
Still the problem is not solved, then
% Save all images name in a sequence manner before doing the operation
% names for example im1,im2,im3...
Hope it helps!