Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using matlab2tikz to import figures from MATLAB to tex.

However I quickly get the message TeX capacity exceeded, sorry [main memory size = 3000000].

I have tried expand main memory using instructions from http://docs.miktex.org/manual/runtimeparams.html using initexmf --edit-config-file=xelatex but that only opens an empty file!

I have also tried to use externalization functionality of pgfplots using instructions from its manual and also from Export eps figures from TikZ, but I've also failed (probably because I am using xetex and not pdflatex).

What should I do furhter?

EDIT: I am using MikTeX 2.9 on Windows 7 (with XeTeX 0.9998)

share|improve this question
    
Check that you haven't any curly brackets that are not closed. –  Yiannis Lazarides Jun 12 '12 at 12:35
1  
Too many points cause this problem. It is ok to get the empty file, just put in the commands in this empty file, save and close. However the memory limit can stiill bea reached, use lualatex to compile, there are no memory limits –  Martin H Jun 12 '12 at 12:49
1  
There is a limit to the memory even if you set it to the max. possible. Try to compile with lualatex for testing. If you have a large number of points in e.g. a plot this always happens. Annoying, I know. I now use lualatex and tikz's external library that renders tikz graphics to pdfs for faster compilation in the future. –  Martin H Jun 12 '12 at 12:59
    
I've got a problem just the same as you mentioned in this post. I tried to download the modified matlab2tikz file but seems that it can't be downloaded. Please can you help me with refreshing the download link ?I'm in urgent. Thanks in advance Catherine –  cathy Sep 4 '12 at 13:09
add comment

2 Answers

up vote 14 down vote accepted

Since I didn't have any luck with altering the TeX memory capacity, I had to find another way to solve my problem.

It was matlab2tikz that actually did the job. It has an option of downsampling the figures during the conversion to tikz-pgf. It is called minimumPointsDistance.

The final (downsampled) figures where absolutely indistinguishable from the original and MUCH, MUCH more light. Also note, that you don't have to downsample the figures in MATLAB yourself, but just set the minimumPointsDistance which only affects matlab2tikz's output code.

EDIT: This is an expansion of my answer. I apologise for getting out of the TeX limits, but this extension offers a better solution, so I believe it should be posted here. Now on the problem...

matlab2tikz's point reduction algorithm although fast and simple has a

main disadvantage

It can distort certain "stiff" areas of the curve when the actual number of points kept drops very low. This is illustrated in the following picture

enter image description here

The blue curve (1184 points) is the original while the red one (117 points) is the reduced. The distortion is obvious.

To deal with this and at the same time keep the number of points low I wrote a new point reduction algorithm which is much more effective (but can be slower sometimes). The results (red curve is 116 points)

enter image description here

It is clear that the distortion is gone.

But there still is

one more disadvantage

that exists in both algorithms. When one converts a batch of figures to tikz, they usually want uniform quality for all reduced diagrams. But sometimes this is not possible (at least without extra effort) because typically minimumPointsDistance must be set differently for each one of the figures and the results actually depend on the size of the intervals [min_y, max_y] and [min_x, max_x] as well as the number of points in the figure.

So in order to overcome this problem and make minimumPointsDistance able to be set at a specific value uniformly for all figures, producing reduced versions of uniform quality, normalisation is used, and now minimumPointsDistance "internally" refers to the actual size of the printed-on-paper figure.

You can download the modified matlab2tikz.m file from here along with instructions.

NOTE that exhaustive tests were NOT made so be careful!

share|improve this answer
    
If the file can't be downloaded, please post a comment so I can fix it. –  niels Sep 4 '12 at 20:16
    
Any chance you could update this for the latest version of matlab2tikz? or better yet, contribute the code to the 'matlab2tikz' author? –  lyxicon Oct 8 '13 at 20:20
    
@lyxicon As mentioned in the copyright notice; I do not claim any copyright, so the matlab2tikz author is free to use the new point reduction algorithm. I'll update to the new version soon. –  niels Oct 11 '13 at 8:10
    
It would be nice if you could share point reduction algorithm as a separate file. –  Ali Nov 9 '13 at 11:11
add comment

As nice and flawless the usage of such a plug-in can be, the TeX memory problems are quite annoying in the long run and I had them many times as well processing spectral data.

Another way to deal with it is to use LuaLaTeX as those memory restrictions do not apply here. Together with the externalize library from tikz, the finished pictures get converted into single PDF files. This makes subsequent compiling fast again.

share|improve this answer
add comment

protected by Community Mar 5 at 17:26

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.