The aim of this function is to create a tex-code picture of a Matlab figure in PSTricks syntax. The tex-file picture can still be adapted after creation and may be either a standalone tex-file or a file to be included in a larger document. The LaTeX packages pstricks, pst-node, pst-plot, pst-circ and moredefs are required. An minimal example latex code is generated at each time this script is run. The matlab code is based on the fig2tex file by Ercan Solak in 2005.

* 2D plots with arbitrary number of lines and patches
* Linear and logarithmic axes and second y-axis
* Grids, subgrids, ticks and subticks
* Arbitrary colors, linestyles and markers
* Labels, title, legend and colorbar
* Annotations (TextArrows) are supported
* GUI, where the fontsize, the plotsize and the export file can be set
* Lines with many datapoints can be compressed in order to reduce file size and compilation time (copied from Matfig2PGF by Paul Wagenaars in 2008)
* Convergence Triangles can be shown for logarithmic plots
* Support of additional code in PSTricks syntax
* Standalone Option for creating high quality cropped pdf-files

Hi Peter, I made some changes to your script regarding the use of pdflatex, now the files created use ifpdf package to compile for pdflatex and latex. I didn't know where to put it, so you can find it here: http://pastebin.com/cHGqD9a5

Also, I found a bug when you have points outside of the axis size, in which those points are removed from the plot.

I'm not sure if my approach is correct or not, but did the job for my test scenarios. Also, it may help others.

@adin: I can't provide any support and/or changes on the script no longer. I have never tested the \usepackage[pdf]{pstricks} version of pstricks but it could work.
Regarding the one/two column document: I recommend to export two versions of the figure, one for each version of the document. The best way is to write the default configuration to the "globals" struct and run the script with "fig2texPS(fignum,globals)".

Hi, I love your script. It work really good. However, I'm struggling with a couple of things.
First, it would be great if you add an option for pdflatex. You can compile it using \usepackage[pdf]{pstricks} instead of the normal pstricks header that you already have. However, this only works for the stand alone version. Which creates my second issue.

The thing is that if you have a two column document, the size of the document is fixed, is there a way to make it change with the \linewidth. So it will be relative to one or two column documents.

The marker legend problem is solved. It was not the script. (fig2texPS is a great script!!) It was XeLaTeX !! Compiled with LaTeX and converted with dvips and epstopdf, I obtained a perfect PDF graphic file. Wondeful.

@ Bertrand Scherrer: Thank you for your help. I have integrated your code to the latest version 0.5.2 that can be found here:
http://fig2texps.peter-scholz.net
The borders of the text boxes are now also shown. But there is still some finetuning to implement, e.g. an automatic linebreak for longer text. I will do that when I'll find some time for that :-)

@ Pia: I have tested your given errorbar with the newest version V.0.5.1 and it works fine without errors. Please test again with the same version and send me your tex-file if it still not works. Peter

I have trouble exporting errorbar plots. Do the package support these? A simple plot like

errorbar(1:10,sin(1:10),0.1*sin(1:10))

exports fine (apparently, not errors at least), but after compiling, my DVI viewer simply stalls with weird errors. If I try to convert the dvi document to a pdf, my GhostScript simply tells me there was an unrecoverable error, and that it stopped.. :(

As I've said before: it would be really nice if there was an option to export to a stand alone tex file with correct paper sizes that then could be converted to a PDF via ps2pdf. This way, users of pdflatex can also use this package.

Great submission! very much what I was looking for - am having problems though adding text to the figure itself (using Matlab's text() command) - and ignore my last rating, that was an accident! 5 stars.

??? Error using ==> figure
Error using ==> figure
Cannot set DockControls to 'off' while WindowStyle is 'docked'

Error in ==> fig2texPS at 891
fig.figh=figure('Name','Figure that will be converted to TeX',...

Might be a conflict with
set(0,'DefaultFigureWindowStyle','docked');

Updates

15 Sep 2009

Warning, if the 'DefaultFigureWindowStyle' is 'docked'

10 Dec 2009

Changes to Version 0.42:
* More possible locations for the legends
* Linewidths of the global struct can now also be strings
* Linestyles adapted
* Enhancements for TextArrows
* Questiondialog, if the tex file already exists
* Small bugfixes