julianfperez
julianfperez

Reputation: 1744

Size and resolution from an image saved as a graphic format file in Matlab

I have the following code to save a plot to a graphics format file. My problem is the image obtained. If I save the image as a bmp image or as the others formats (for example, jpeg image), the appearance is different (resolution and size). I would like to know how I can fix this.

X = 0:pi/100:2*pi;
Y = sin(X);
fh = figure('toolbar','none','menubar','none');
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]); 
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);

Upvotes: 1

Views: 247

Answers (1)

Jonas
Jonas

Reputation: 74940

Whenever you have an issue saving a plot to a nice-looking graphics file, you should look into the excellent export_fig on the Matlab File Exchange. In the unlikely event that export_fig is unable to do something you need, the file's author is very responsive (contact him by e-mail).

Upvotes: 1

Related Questions