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!