MATLAB: I am getting the error while reading the images

errimage processing

ipDir = '../Dataset/photos'; isDir = '../Dataset/sketches';
files_p = dir([ipDir '*.jpg']); files_s = dir([isDir '*.jpg']);
tmp1=imread([ipDir files_p(1).name]); Index exceeds matrix dimensions.
Error in createTrainingData_color (line 13) tmp1=imread([ipDir files_p(1).name]);
I am getting the above error. Please help me.
I am getting the error while reading the images.

Best Answer

Evidently the length is zero and so when you try to access index 1, it says "Index exceeds matrix dimensions." Try this more robust way:
if length(files_p) > 0
fullFileName = fullfile(ipDir, files_p(1).name);
tmp1=imread(fullFileName);
end