Concatenate a file path in copyfile
Mostrar comentarios más antiguos
I am attemtping to create a series of files I load into a script . This series of files will have a variable changed in each of them. What i'd like to do is create the variable, the directory of the scenario file, and, using copyfile, move the desired files from the template scenario to the new scenario file. The file name is currently concatenated correctly using mkdir, but cant seem to figure out how to concatenate the file path using the value of the variable I call 'noSpaceBetweenUs,' which I need to do both for the copyfile line, and the cd line in the code.
function startup
cd ~/Desktop/program/scenario/
%
for X= 100:100:500
noSpaceBetweenUs=mkdir(['ScenarioSpacing' num2str(X)]) %
copyfile(['scenario','/*.prm'],'~/Desktop/program/scenario/' convertStringsToChars(noSpaceBetweenUs)]) %(i want the value of noSpaceBetweenUs after that forward slash)
cd(['~/Desktop/program/Scenario' convertStringsToChars(noSpaceBetweenUs)])
%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.
end
Appreciate the help!
2 comentarios
Stephen23
el 22 de En. de 2019
Do NOT use cd in code. Changing directory is slow and makes debugging much harder.
All MATLAB functions that read/write data files accept absolute/relative filenames, so there is absolutely no need to change the current directory. Using absolute/relative filenames is faster than changing the current directory.
Do not use concatenations to build filepaths. It is recommended to use fullfile, which automatically handles the file separator character.
Charles Cummings
el 22 de En. de 2019
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre File Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!