I have multiple images I want to crop them and save them in another folder. The code that I am using is given below.
myFolder = 'jpg';
filePattern = fullfile(myFolder, '*.jpg') ;
theFiles = dir(filePattern);
numberOfFiles = length(theFiles);
I = imread(images(1).name) ;
[x, rect] = imcrop(I) ;
for i = 1:numberOfFiles
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
I = imread(fullFileName);
I = imcrop(I,rect) ;
fullFileName = fullfile(images(i).folder, ['cropped' images(i).name]);
But No folder is generated which contains the cropped images . Also I am getting the following error
Index exceeds the number of array elements (0).
Error in cropimages (line 5)
I = imread(images(1).name) ; % crop one to get rect
Can someone help me to solve this problem?