Copy a file *.m into newly made folder (folder5, folder6, folder....)
Ältere Kommentare anzeigen
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 Kommentare
Rik
am 23 Apr. 2021
But you are already using sprintf. What don't you understand? Did you do a basic Matlab tutorial?
Yogesh Bhattarai
am 23 Apr. 2021
Rik
am 23 Apr. 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
am 23 Apr. 2021
Yogesh Bhattarai
am 23 Apr. 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
am 23 Apr. 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
am 24 Apr. 2021
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Debugging and Analysis finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!