nschloe/matlab2tikz — Issue #60: Corner case error in function splitByArraySize
Author: burkart
Created: 2012-01-17 07:10:56+00:00
State: open

When saving figures using matlab2tikz that have a number of points which is a multiple of 4000, an error is produced.

Example code:

```
x=1:4000;
y=rand(1, length(x)).*100;
plot(x, y, 'b+')
matlab2tikz('000.tikz', 'showInfo', false)
```

This yields the following error message in MATLAB:

```
??? Attempted to access xDataLeft(1,1); index out of bounds because size(xDataLeft)=[0,1].

Error in ==> matlab2tikz>splitByArraySize at 1447
xDataExtra(end) = xDataLeft(1,1);

Error in ==> matlab2tikz>splitLine at 1098
[xDataCell , yDataCell] = splitByArraySize( xDataCell, yDataCell );

Error in ==> matlab2tikz>drawLine at 930
[xDataCell, yDataCell] = splitLine( m2t, xData, yData, xLim, yLim );

Error in ==> matlab2tikz>handleAllChildren at 420
[m2t, env] = drawLine( m2t, child );

Error in ==> matlab2tikz>drawAxes at 731
[ m2t, childrenEnvs ] = handleAllChildren( m2t, handle );

Error in ==> matlab2tikz>saveToFile at 335
m2t = drawAxes( m2t, visibleAxesHandles(ix(k)), alignmentOptions(ix(k)) );

Error in ==> matlab2tikz at 266
saveToFile( m2t, fid, fileWasOpen );
```

The same error occurs if x in the example above goes from 1 to 8000 or any other integer multiple of 4000. All non-multiples work fine (although obviously that wasn't tested exhaustively).

As a side note, the figure which originally showed this bug is quite a bit more complicated than the example given above (e.g. multiple plots within one figure) and the critical number of points for that plot is not 4000 but a seemingly arbitrary 5304. However, the root cause of accessing a certain element out of a 0x1 (empty) matrix remains the same, therefore I'm confident that fixing this bug for the example above also fixes it for my original figure.