Home > MATLAB, Tips > Exporting from MATLAB to eps

Exporting from MATLAB to eps

I had some trouble today trying to convert one mesh figure to an eps file to use it in LaTex. First the face color in the mesh wasn’t properly set when I exported, MATLAB create some annoying margin around the eps file and the margins were not as tight as possible.

Any way I found good information in the web.  But I cannot finish my task automatically as I wanted. I will explain a little bit about how to publish a good figure in few steps.

First prepare your figure — do some plots –, and store the handler

h = figure(1);

Then,  — it is supposed to work, or you can use another method — you set the margins tight

iptsetpref('ImshowBorder','tight')

And for a good final look you need to set the background to other color that is different from the default gray

set(h,'Color','white')

This part is important if you are trying to change the faces color in a 3D plot, if you don’t change this value the faces are not rendered properly.
Now let’s print the figure to an eps file using -depsc2 driver and for a good result use a vector graphics output, using the painters render er

print(h,'-depsc2','-painters','figure.eps')

This should do the magic. Although, for me the margins wasn’t tight enough. I solve this problem by editing the eps file by hand. Open it with a text editor and change the lines (all of them)

%%BoundingBox: x-ll y-ll x-ur y-ur

where:

  1. x-ll is the x-coordinate of the lower-left corner of the BoundingBox.
  2. y-ll is the y-coordinate of the lower-left corner of the BoundingBox.
  3. x-ur is the x-coordinate of the upper-right corner of the BoundingBox.
  4. y-ur is the y-coordinate of the upper-right corner of the BoundingBox.

That make good figures. You can change the size of the paper too, and other properties before printing.

Categories: MATLAB, Tips Tags: , ,
  1. August 5, 2010 at 2:38 am

    To get a tight fit I would often do the following:

    >> print(gcf,’-despc2′,’file.eps’)
    >> !ps2pdf -dEPSCrop file.eps

    Also, at the end of the day it is worthwhile to purchase Adobe Illustrator and tweak figures manually (removing all those silly padding regions).

  1. August 17, 2011 at 9:05 pm
  2. January 25, 2012 at 3:42 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: