MATLAB: Can I update multiple MAT files at the same time to use the MATLAB 7.0 (R14) compression format

convertfilematMATLABmultipleupdate

I upgraded to MATLAB 7.0 (R14). I would also like to upgrade my MAT files to use the new compression format. However, I have many MAT files, and it takes a long time to re-save my MAT files one by one.

Best Answer

The ability to convert multiple MAT files at the same time is not available in MATLAB 7.0 (R14).
To work around this issue, you can retrieve a list of every MAT-file located in the directory of interest using the WHAT command, and then utilize a FOR loop to load and save the MAT files individually. For an example of a script that does this, see the following function:
function updateCompression(location)
clear
location = cellstr(location);
filelist = what(location{:});
for i = 1:length(filelist)
file = filelist(i).mat;
for j = 1:length(file)
loadsave();
end
end
function loadsave()
load(evalin('caller','file{j}'))
save(evalin('caller','file{j}'))
The ‘updateCompression’ function inputs a cell string variable that represents a list of directories in which your MAT-files are located. Note that you can also use the following syntax to call the function to gather all MAT-files in the MATLAB search path, including any files provided by the MathWorks:
updateCompression(char(0));
This function will go through every MAT files in the specified directories, and call the ‘loadsave’ subfunction. Using MATLAB 7.0 (R14), this subfunction will load the MAT-file in question and resave it using the new MATLAB 7.0 (R14) compression format. Note that to avoid cluttering the workspace in which the MAT-files are loaded, the EVALIN command is used to retrieve the file in question. This way, ‘loadsave’ function workspace is reserved solely for the content of the MAT-files.