MATLAB: Do some of the entries in history.m get erased arbitrarily

MATLAB

Based on the documentation, I expect the command history file to grow to 200KB, and overwrite the oldest commands first after that.  However, my experience is that the size of the file is on average between 4 to 6 KB, and never reaches the documented 200 KB size.  I also notice that some of the oldest commands are missing sometimes.  Running a job using MATLAB in the "-nodesktop" mode, and seems to be the cause of the file shrinking.  If I have an interactive session of MATLAB open, no commands are lost.  What could be causing this?

Best Answer

The old implementation of the "-nodesktop" history has a 4 KB  limit and writes to the same "history.m" file as the desktop command history.  As of MATLAB R2014a, the desktop writes to a different file, "history.xml", and therefore the commands will not be lost due to running in "-nodesktop" mode.
With older versions of MATLAB, to avoid losing entries in 'history.m', either:
1) Avoid running in -nodesktop mode when possible.
2) Temporarily move the 'history.m' to a different directory before launching MATLAB in "-nodesktop" mode, then copy it back to the original location later.