MATLAB: How to get an ASCII file with the variable names and values of variables I have saved in a binary MAT-file in MATLAB 7.6 (R2008a)

MATLAB

I am trying to get an ASCII file with both the names and values of the variables in my MATLAB workspace. I have tried using the SAVE command as shown in the following example, however the resulting ASCII file only shows the variable values, not the variable names. I would like both to show up.
z1 = 1;
z2 = 3;
z3 = 20;
save filename1 z* -ascii

Best Answer

The ability to get both the variable names and variable values into an ASCII file using the SAVE command is not available in MATLAB 7.6 (R2008a).
To work around the issue, it is possible to read the variable names and values from a MAT-file and print them to an ASCII text file. Download the attached file 'createAsciiFile' and try the following example:
z1 = 3;
z2 = 20;
z3 = 13;
save foofile.mat z*
createAsciiFile('foofile.mat');
'createAsciiFile' will create a text file with the same name as the MAT-file, so in this example, it will create 'foofile.txt'.