MATLAB: How to sort images from a folder in subfolders using the data from a excel/ .mat file

importing excel dataMATLABsort

Hello, I have a dataset with flowers (8000 pictures) and i need to sort them in subfolders (rose, tulip, etc) and i have the imagelabel.mat witch is a double value (1×8000) where i can see how many examples are for each class. How can i sort them without having to create folders and copy-paste the images in folders? A code example would help a lot. Thanks

Best Answer

You need to iterate through your dataset and ensure the necessary subfolder exist, then move the file
% concat sub folder path
subfolderPath = [parentDirPath '\' flowerName];
% check if subfolder exists
if ~exist(subfolderPath, 'dir')
% create subfolder
mkdir(subfolderPath);
end
% move file from original path to subfolder
[status, msg] = movefile([parentDirPath '\' fileName], [subfolderPath '\' fileName]);
% check if file moved successfully
if ~status
% log error
end
That's the general idea