Copy a file *.m into newly made folder (folder5, folder6, folder....)
Mostrar comentarios más antiguos
for n = 1:n
mkdir(['folder',sprintf('%d',n)])
end
path1= 'folder(num2str(n))'; %%???? Here I got error for the path name
dos(['copy *.m ', path1])
8 comentarios
Rik
el 23 de Abr. de 2021
But you are already using sprintf. What don't you understand? Did you do a basic Matlab tutorial?
Yogesh Bhattarai
el 23 de Abr. de 2021
Rik
el 23 de Abr. de 2021
You show in your for loop that you know how to create a folder name. You use sprintf to create the folder name for mkdir. Why don't you do the exact same thing to create the path1 variable?
for n = 1:n
mkdir(sprintf('folder%d',n));
end
path1=sprintf('folder%d',n);
dos(['copy *.m ', path1])
Yogesh Bhattarai
el 23 de Abr. de 2021
Yogesh Bhattarai
el 23 de Abr. de 2021
Rather than very smelly copying of m-files into directories, most likely a much better approach is to use absolute/relative filenames when accessing data files.
Rik
el 23 de Abr. de 2021
Have you read the documentation for sprintf? It should be easy for you to add a second number if you did.
You should also take the advice from Stephen to hart.
Yogesh Bhattarai
el 24 de Abr. de 2021
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Debugging and Analysis en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!