MATLAB Answers


Looping through command mkdir

Asked by Charles Cummings on 18 Jan 2019
Latest activity Commented on by Charles Cummings on 18 Jan 2019
For a bit of context, I am trying to create a series of 20000 scenarios given an input parameter of my choosing, and label those newly created files with a file name and the numeral of the paramter I am changing. Below is a portion of the script
function startup
cd ~/Desktop/program/scenario/
for X= 100:100:500
mkdir Scenario-NumberX %X is the changing variable which a file name will be made
cd ..
%under 'scenario' should be a number of files of my choosing with parameter files
% each iteration through the loop should be creating a file and placing it in the desired location.
Any and all help is appreciated!


The mkdir function creates a new directory (folder) not a new file.
Are you sure you want to do that?
Yes apologies, misspoke. I have prm files in another folder I am moving into it every iteration.

Sign in to comment.

1 Answer

Answer by Sean de Wolski
on 18 Jan 2019
 Accepted Answer

for ii = 1:10
mkdir("Scenario" + x)


Show 1 older comment
Also, I havent been able to use that scenario directory created inside of copyfile ie as a loaded variable
This works in newer releases. In older releases
mkdir(['Scenario' num2str(ii)])
Perfect thank you. The other issue was taking that name I created with mkdir and adding it to the end of copyfile. Tried this
copyfile(['scenario','/*.prm'],['~/Desktop/program/scenario/Scenario-NumberX' convertStringsToChars('Scenario100')])
Should I create a new thread?

Sign in to comment.