MATLAB Answers

0

Create new dynamic Subfolder and dynamic content

Asked by MrMedTech on 22 Apr 2016
Latest activity Edited by Walter Roberson
on 22 Apr 2016
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 Comments

Sign in to comment.

0 Answers