MATLAB: How to rename variables in a MAT-file that have invalid characters in the variable name in MATLAB 7.0.1 (R14SP1)

charactersdataimportinvalidMATLABnamerenamevariable

When I use a MAT-file that is generated from an external source outside MATLAB, variables can be saved with invalid characters in the variable name (for example L/D). I cannot access these variables and they cannot be renamed from the workspace. I can open the MAT-file in MATLAB 6.5 (R13) but I cannot use the variables. I can not open the MAT-file in MATLAB 7.0.1 (R14SP1).

Best Answer

This enhancement has been incorporated in Release 2006b (R2006b). For previous product releases, read below for any possible workarounds:
If you want to be able to use these variables in MATLAB 6.5 (R13) or MATLAB 7.0.1 (R14SP1), you will need to rename the variables in MATLAB 6.5 (R13) and then resave the MAT-file with valid variable names. To rename your variables in MATLAB 6.5 (R13), perform the following steps:
1) Select "Import Data..." from the "File" menu in MATLAB.
2) Select the file containing the variables and click "Open".
3) When the Import Wizard opens, make sure that the check marks next to the variables with invalid characters are checked and click the "Finish" button. This will open the variables with the "/" characters replaced with "_" characters.