How to save multiple images in the same folder?
2 次查看(过去 30 天)
显示 更早的评论
hello, I have several images that are saved in different folders and I want to arrange theses images in a single folder. please, any suggestion of matlab code? thanks in advances
0 个评论
采纳的回答
Image Analyst
2016-1-1
Perhaps use my demo. In the middle of the loop is where you would stick a call to copyfile() or movefile().
更多回答(1 个)
Walter Roberson
2016-1-1
The function you supply would movefile()
Watch out for duplicate file names! Watch out for bugs while you get the code working...
If I were developing the code, I would refrain from moving the files unless I had good reason. I would either copy the files or I would create links to the files.
2 个评论
Walter Roberson
2016-1-4
sourcedir = fullfile(pwd, 'flowers');
destdir = fullfile(pwd, 'flowerCategory');
if ~exist(destdir,'dir')
[success, message, messageid] = mkdir(destdir);
if ~success
error(messageid, sprintf('Failed to create directory "%s" because "%s"', destdir, message) );
end
end
%find the potential source directories
dinfo = dir( fullfile(sourcedir, 'category*') );
%remove everything that is not a directory
dinfo(~[dinfo.isdir]) = [];
for J = 1 : length(dinfo) %for each source directory
thisdir = fullfile(sourcedir, dinfo(J).name);
%find potential files in directory
finfo = dir( thisdir );
%get rid of the things that are not files
finfo([finfo.isdir]) = [];
for K = 1 : length(finfo) %for each file in directory
thisfile = fullfile(thisdir, finfo(K).name );
%make a copy of it
copyfile(thisfile, destdir);
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!