2

My question is about including MATLAB exported images in LaTeX. I need it to be a vector graphic image. I have spent a lot of time trying to search for an answer. It is with great hesitation that I am asking this question, knowing that probably I would have skipped through some specific answer in my searches somehow. Nonetheless, I had found two solutions which are generally used:

  1. exporting MATLAB image as an eps file and then importing into LaTeX
  2. using matlab2tikz and exporting MATLAB image as a tikz file and then inputting the tikz file

I tried to work with tikz. The images turn out to be good. but the text in the image is really weird and it took me an unnecessarily high amount of time to make it work- especially when it comes to adjusting the images in the document and placing multiple images together.

Theoretically, the eps solution sounded perfect and would be perfect if I could just export simply from matlab without any glitches and import into latex just like any other png or jpeg file. I was thinking that importing an image wouldn't be so difficult. SO here's what i did:

I exported my figure from MATLAB, both - directly by selecting .eps option, and by using export_fig. Then I imported it into LaTeX with

\begin{figure}[t]
\centering
\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(0,0)(5,2)
    \rput[bl]{0}(0,0){\includegraphics[width=8\psxunit]{figures/myfig.eps}}
    \rput[bl]{0}(8,0){\includegraphics[width=8\psxunit]{figures/myfig.eps}}
\end{pspicture}
\end{figure}

However, when i include it, the figure contains a white mesh as shown below, which shouldn't be there. enter image description here

I tried a few solutions to this as follow:

  1. Replacing some lines of text in the eps file There are two problems with this method that I faced. The first is that this is a pain to do for every file (which would possibly be in hundreds) that I export. And the second is that despite doing this it still shows the mesh, but this time for only certain areas of the figure. I tried searching for more instances of the \f\fill line which the post talks about, but there exist none.
  2. Using opengl as the renderer while exporting from as an eps from MATLAB. While using this solution did get rid of the lines, opengl renders the image as pixels and not as a vector graphic. So the quality of the image deteriorates on zooming. So this isn't acceptable.

My question is as follows: Is there an easy way to export an eps file from matlab and use it in LaTeX without having to change the text in the eps file?

eigenaus
  • 76
  • 1
  • 7
  • Can you please add the Matlab2TikZ version of the image in your post? You might want to read this as well: https://community.adobe.com/t5/indesign/why-white-lines-on-pdf/td-p/8823035?page=1 – pluton Aug 10 '20 at 16:00
  • Note that your figure could be completely created with Tikz without the shown issue. Essentially, Matlab uses a grid to fill up the ellipse with the green color and shows these annoying yet (apparently) unavoidable white lines. – pluton Aug 10 '20 at 16:06
  • Maybe saving to PDF in MATLAB (and cropping afterwards if necessary) would give better results? See for example https://www.mathworks.com/matlabcentral/answers/311820-save-a-figure-as-pdf for some pointers. – Marijn Aug 10 '20 at 19:19

0 Answers0