Automatic choice of graphics format file for print command
Show older comments
I have the following code:
X = 0:pi/100:2*pi;
Y = sin(X);
fh = figure('toolbar','none','menubar','none','Units','characters');
Pan1 = uipanel(fh,'Units','normalized','Position',[0 0 0.5 1],'title',...
'Panel1');
Pan2 = uipanel(fh,'Units','normalized','Position',[0.5 0 0.5 1],'title',...
'Panel2');
haxes = axes('Parent',Pan2,'Units', 'normalized','Position',...
[0.125 0.1 0.75 0.75]);
hplot = plot(haxes,X,Y);
xlabel(haxes,'Time (second)');
ylabel(haxes,'Amplitude (meter)');
title(haxes,'Sine function');
FileName = uiputfile('*.bmp;*.png;*.jpg;*.tif','Save as');
ftmp = figure('Menu','none','Toolbar','none','Units','normalized',...
'Position',[-1000 -1000 1 1]);
set(gcf,'PaperPositionMode','auto');
set(gcf,'InvertHardcopy','off');
new_axes = copyobj(haxes, ftmp);
set(new_axes,'Units','normalized','Position',[0.1 0.1 0.8 0.8]);
saveas(ftmp, FileName);
delete(ftmp);
delete(fh);
I have two problems:
Number #1: I want the background color of the figure printed to be gray. For this reason, I use the command
set(gcf,'InvertHardcopy','off'); However, when I save the image as a bmp format file, it appears an upper white strip on the image printed. This strip does not appear when the remaining formats (i.e., png, tif and jpg) are used.
Number #2: I want to change the command saveas by print and allow it to select the graphics format file automatically. One possibility is:
[FileName,PathName,FilterIndex] = uiputfile('*.bmp;*.png;*.jpg;*.tif','Save as');
ftmp = figure('Menu','none','Toolbar','none','Units','normalized',...
'Position',[-1000 -1000 1 1]);
set(gcf,'PaperPositionMode','auto');
set(gcf,'InvertHardcopy','off');
new_axes = copyobj(haxes, ftmp);
set(new_axes,'Units','normalized','Position',[0.1 0.1 0.8 0.8]);
switch FilterIndex
case 1 % graphics format file is bmp
fmt = '-dbmp';
case 2 % graphics format file is png
fmt = '-dpng';
case 4 % graphics format file is jpeg
fmt = '-djpeg';
otherwise % graphics format file is tiff
fmt = '-dtiff';
end
print(ftmp,fmt,FileName,'-r200');
delete(ftmp);
delete(fh);
What are the alternatives solutions to my problems? How I could change the line
print(ftmp,fmt,FileName,'-r200');
by
print -r200 fmt FileName;
without getting an error?
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!