MATLAB: How to delete variables in the MAT-file without loading them into MATLAB 7.2 (R2006a)

deletematmatfileMATLAB

I would like to delete variables in a MAT-file without loading them into MATLAB first.
For example, I have a file called myFile.mat which contains many variables resulting in a large MAT-file which is slow to load. I don't need all of the variables in the file.

Best Answer

MATLAB itself does not offer any functionality for deleting a particular variable from a MAT file.
 
However the MAT FILE API provides the matDeleteVariable function which allows you to delete a variable from a MAT file by its name. You can create a small MEX function in order to call matDeleteVariable. An example is attached.