Move file into folder
1 次查看(过去 30 天)
显示 更早的评论
I want to move a created file into created folder. Where is wrong in my code:
for ii=0:10:360
for jj=0:10:90
%%%create a multiple folder
newdir=sprintf('view%2d',ii,jj);
mkdir(fullfile(newdir));
%rotate masks
for i=1:360
rotate(aa,[0,0,1],1);
% print figure with rotate
eval(['print -dpng Slice_' num2str(i) '.png']);
%move figure into folder
movefile('Slice_(i),view%2d',ii,jj')
% pause time
pause(2);
end
end
end
0 个评论
采纳的回答
Guillaume
2016-8-31
编辑:Guillaume
2016-8-31
newdir = sprintf('view%2d', ii, jj);
Is it really the intent that the format string only has one input, yet you pass two inputs to sprintf? You will end up with the string 'view10view15', if ii = 10 and jj = 15. If that really is the intent, then a comment saying so should be added, or better, make it explicit that it's wanted:
newdir = sprintf('view%2dview%2d', ii, jj);
Next,
mkdir(fullfile(newdir));
is a bit unconventional. You normally pass at least two parameters to fullfile. As it is, in my version of matlab this will normalise the folder separator, but that's not a documented behaviour.
Next,
eval(['print -dpng Slice_' num2str(i) '.png'])
Ewww! Why the eval? It serves absolutely no purpose other than slowing down the code, making it impossible to debug and hiding all the syntax errors. How about:
printf('-dpng', sprintf('Slice_%d.png', i));
Finally,
movefile('Slice_(i),view%2d',ii,jj')
since when does movefile takes a number as the second and third argument? That line makes absolutely no sense. Perhaps you meant:
movefile(sprintf('Slice_%d.png', i), newfolder);
But anyway, why not directly create the file in the correct folder:
filename = sprintf('Slice_%d.png', i);
print('-dpng', fullfile(newfolder, filename)); %and even better would be to pass the figure handle to print.
%no movefile needed, the file is already where you want it.
2 个评论
更多回答(2 个)
michio
2016-8-31
How's trying
filename = ['Slice_',num2str(i),'.png'];
movefile(filename,newdir);
instead of
movefile('Slice_(i),view%2d',ii,jj')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!