matlab2tikz - TeX out of memory

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!


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.