1
\$\begingroup\$

This script can successfully go through all of the subdirectories in a root directory, and then process a specific file that exists in all of them and output the file in the root directory as a .png named after the subdirectory. I am hoping to get some advice for the end of the script in formatting the name of the image since I do a quick post-processing step with imageMagick but the naming convention of the folders when they are generated is such that they do not have preceeding zeros:

Checkpoint0

Checkpoint1000

...

Checkpoint10000

...

Does anyone have a suggestion for how to nicely parse the number of digits in the longest foldername and use that to add an appropriate number (either exact or one additional) of zeros to the corresponding image names?

close all;
clear all;
pkg load all;
addpath("~/workspace/PetaVision/mlab/util");

dirData = dir(pwd);
dirIndex = [dirData.isdir];
folderList = {dirData(dirIndex).name};

pvpFile = "W1_W.pvp"
nbins = 100;
xmin = -15;xmax = 15;
ymin = 0;ymax = 150000;

for i = 3:size(folderList,2)
filename{i-2} = strcat(folderList(1,i),"/",pvpFile);
temppvp = readpvpfile(cell2mat(filename{i-2}));
cpList{i-2} = temppvp{1}.values{1};
end

for i = 1:size(cpList,2)
    histfit(cpList{i}(:),nbins);
    xlim([xmin xmax]);
    ylim([ymin ymax]);
    xlabel('Weight');
    ylabel('Frequency');
    title(folderList(1,i+2));
    imgTitle = cell2mat(strcat(folderList(1,i+2),"_",pvpFile))
    print(imgTitle)
end 
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.