1

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);
julianfperez
  • 1,726
  • 5
  • 38
  • 69
  • 2
    Use `export_fig`: http://www.mathworks.com/matlabcentral/fileexchange/23629 – Jonas Nov 18 '11 at 03:50
  • 1
    possible duplicate of [How to set the plot in matlab to a specific size?](http://stackoverflow.com/questions/7561999/how-to-set-the-plot-in-matlab-to-a-specific-size) – Jonas Nov 18 '11 at 03:51
  • @Jonas: Thank you for your comment. If you write it as an answer, I would be pleased to accept it. – jfpeji – julianfperez Nov 23 '11 at 23:25

1 Answers1

1

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).

Jonas
  • 74,690
  • 10
  • 137
  • 177