Variable file name in print function using object handle
이전 댓글 표시
I am trying to save a file using its handle. The name of the file is variable. How do I do it using the print function?
My attempt:
for i = 1:100
var = int2str(i);
z = strcat(var,'.bmp');
I = imread(z);
imhist(I);
h = gcf;
print(h, '-dbitmap' , 'D:\Figures\z');
end
I get a file named z.bmp instead of the string. How do I change the code to save the file as a string contained in z?
답변 (1개)
The problem is you wrote the whole name as a literal string instead of using the variable--
print(h, '-dbitmap' , fullfile('D:\Figures',z));
NB: that as you have it written, your filenames will be just '1.bmp', '2.bmp', etc., ... That may be ok and what you intend but you might consider a little more sophistication in naming as sotoo
print(h, '-dbitmap' , fullfile('D:\Figures',sprintf('Fig%02d',i)));
This will produce 'Fig01', 'Fig02', etc., ... which will sort alphabetically numerically as well when get to double-digits and will also identify figure files as figures besides the extension (which Matlab automagically supplies according to the type specified so don't need to create it explicitly). Just a suggestion...
카테고리
도움말 센터 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!