Copy a file *.m into newly made folder (folder5, folder6, folder....)
显示 更早的评论
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 个评论
Rik
2021-4-23
But you are already using sprintf. What don't you understand? Did you do a basic Matlab tutorial?
Yogesh Bhattarai
2021-4-23
Rik
2021-4-23
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
2021-4-23
Yogesh Bhattarai
2021-4-23
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
2021-4-23
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
2021-4-24
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!