Create new dynamic Subfolder and dynamic content

2 次查看(过去 30 天)
Hey everybody.
During my last project I had to create a new SubFolder within some snapshots I made.
The intention was to create a new Subfolder for every run of the program without using a variable.
Maybe it's not the best solution but it works=)
I hope this might help if you have to do anything similar.
%gives you actual date and time in this format(can be changed see doc)
DateString = datestr(now,'dd_mm_yyyy_HH_MM_SS');
%save the path to your subfolder (here subfolder is Data-dd_mm_yyyy_HH_MM_SS) so you can create a new Subfolder without a variable e.g.
newSubFolder = sprintf('path of your parent folder\\Data-%s', DateString);
if ~exist(newSubFolder, 'dir')
mkdir(newSubFolder);
end
%here I ploted my image in axes(better to use the axes handle than gca here)
F=getframe(gca);
%snaphot is the name of each snapshot I save with a variable number which I increment in a loop. Don't forget the specification .png oder .jpg etc.
snap=sprintf('\\snapshot-%s.png',num);
whole_path=strcat(newSubFolder,snap);
imwrite(F.cdata,whole_path,'png');
cheers

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by