Move file into folder
2 ビュー (過去 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 件のコメント
Guillaume
2016 年 9 月 1 日
編集済み: Guillaume
2016 年 9 月 1 日
Please, spend some time reading the documentation of sprintf and fullfile.
To read your image:
rgbImage = imread(fullfile(newdir, filename)); %no point in recreating the filename string
To save your excel file:
xlswrite(fullfile(newdir, 'test.xlsx'), redArea);
その他の回答 (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!