Moving files to another folder based on a rule Complexity O(n3)
Show older comments
Hello i'm trying to move 25000 of images in 38 folders based on a rule . Each folders represents the class the image belongs to . I also have 38 .txt files that contain the name of images that belong to that class . The complexity of this algoritm is O(n3) , more exactly O(25000*38*~3000). It took me 12 hours to move just 3000 images. It would take me about ~30 days to move all the images. What can I do to optimize my code ?
parfor i=1:length(imNames) %imNames is a vector that contains the name of the 25000 images .
for k=1:38 %number of .txt files
nameOfFiles=filenames(k).name;
% filenames stores the names of the 38 .txt files
nameOfFiles=erase(nameOfFiles,'.txt'); % removing .txt extension of files
for j =1:length(data.(nameOfFiles)) % length of a particular .txt file(number of images within a file)
%data is a struct that has 38 fields/classes each field containing the names of images withing a .txt file
if strcmp(char(imNames(i)),data(j).(nameOfFiles)) %Compares value of vector that contain 25000 values with value from file nameOfFiles
copyfile(char(imNames(i)), nameOfFiles); % copies file to a folder nameOfFiles
end
end
end
end
Answers (0)
Categories
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!