Why is MATLAB crashing when opening exported LabChart files?

LabChart's Export MATLAB standard file format is very efficient. This means that exporting large data files is quick and produces small *.mat files.  However, we occasionally have users contacting us regarding MATLAB crashing in one of the following ways when they try to open elements out of the *.mat file LabChart creates:

  • MATLAB indicates "Too many elements" and crashes.
  • MATLAB indicated 'File corrupt'.

At the core, both messages mean that MATLAB has hit a memory limit. The user is trying to export more data than their installation of MATLAB and computer hardware can cope with.

There are three parts to solving this:

Part 1
To rule out that LabChart is the problem, simply export a much smaller selection of data. The original amount may not seem like 'a lot' in the first place, but the success here is dependent on the memory MATLAB has available.

Part 2
To find out what the memory limit on a MATLAB installation is, create a large matrix within MATLAB and save it and see what happens when trying to re-load it.

e.g. using the command data=zeros(1,1e6) to create an array with 1M samples.

Troubleshooting Steps
The only way to tell the actual limit is seems to be by trial and error, using the following commands in MATLAB:

  1. Create a dummy vector called "data" filled with 1e6, 1e7 or 1e8 zeroes: data=zeros(1,1e8)
  2. Save the dummy vector "data" to "c:\test.mat" in MATLAB v4 file format (which is what we use): save c:\test.mat data -v4
  3. Close MATLAB, restart MATLAB, then try to reload the file: load c:\test.mat
  4. In MATLAB type "whos" to confirm step 3 worked. Otherwise it just works silently, and all you see is the normal MATLAB command prompt. If it's too big to load, it shows the "File corrupt" error.

For example, on one of our test computers, we find that 64-bit MATLAB refuses to load anything larger than 1 x 10^8. The limit for 32-bit MATLAB on the same machine is even lower (about 75,000,000).

Part 3
Finally, to estimate the maximum size of data, simply add up the number of samples in each block and in each channel. The number of samples is shown in the Recorded Data panel that appears when you click-and-hold on the channel in Chart View.

Further reading: