MATLAB slows down while saving large amounts of .mat files
Show older comments
I wrote a sub-automated script that triggers a Lecroy oscilloscope to capture waveforms an then save the waveforms into .mat files in a pre-allocated folder. Every time the scope triggers, the waveforms are saved. When I run the script for some 100 or so trigger events, no significant decrease in the saving is observed. However, when I increase the total number of trigger events to some 700 or so, it is observed that MATLAB takes a long time to save the .mat file and then move on to the next trigger. Is this some issue related to how MATLAB allocates RAM? Are there any suggestions on how to improve the speed?
Answers (1)
Walter Roberson
on 15 Feb 2022
0 votes
If you might be saving more than 2 gigabytes of data in a single .mat, then you must use -v7.3 format -- and that format can be much slower.
The slowness can occur even for smaller files if you explicitly use the -v7.3 option, or if your preferences are set to use -v7.3 automatically.
Generally speaking, large purely numeric arrays are significantly less affected than composite variables such a struct arrays or cell or objects. If I understand the internals correctly, then a struct scalar with one level of fields that are all numeric, should be reasonably fast.
Another potential challenge is that by default both -v7 and -v7.3 want to compress dat; if your data is hardly compressable then that can waste time.
If you are adding new variables to a -v7 mat file each time, the performance should not be bad. If you use a -v7 file in -append mode and overwrite existing variables, performance can get bad.
If you are using a -v7.3 file and using matfile() to update parts of variables, performance can slow down.
1 Comment
Howe Li Yeo
on 16 Feb 2022
Categories
Find more on Oscilloscopes in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!