Monday, March 16, 2009

Appending to .MAT files

You can append variables to a .mat file using

>> save(oFname,'var','-append');

Consider 2 scenarios:
1) The variable 'var' is being added to the .mat file for the first time
2) The variable 'var' already exists in the .mat file and is being overwritten or updated

If 'var' takes up a lot of memory ie it is large matrix or array, (2) is significantly slower than (1) by orders of magnitude.

Moral of the story: As far as possible avoid overwriting or updating a variable in a .mat file, especially if the variable takes up a lot of memory.

No comments: