How to load a file or variable with pure number names, such as 001.mat?

1 view (last 30 days)
We used to save our data series as DM_001.mat all the way up to DM_100.mat.
Data are generated from a network analyzer. It has 801 rows and 2 columns of double number. It is a 801X2 matirx named DM_000, if we load DM_000.mat
Recently, we saved our data as 000.mat till 100.mat.
When we try to load 000.mat, we realized that since matlab doesn't allow variable name to start with a number instead of a letter, we can't load all these 0**.mat files.
Even if we change the file names and add letters at front so that the names become Data001.mat, matlab still can not load them, because in the .mat file, the array or matrix name was saved to be 000, instead of starting with a letter.
Now how can we load or read these .mat files and get the 801X2 matrix?
Is there a way to change the variable name in the 001.mat file so that matlab can read it?
Thank you a lot.

Answers (3)

Jan
Jan on 31 Oct 2011
If Walter's suggestion "S=load" does not help, because the names of the variables are coruppted also, see this thread:
You can load MAT files containing invalid names for variables directly to the workspace in Matlab 2009a. But then you need the C-Mex file, to access these variables. Which Matlab version are you using? Does the new MAT-file access function in 2011b help to get a single variable form the file, even if the name is no valid Matlab symbol?

Walter Roberson
Walter Roberson on 31 Oct 2011
If you load using the structure output format
S = load('001.mat');
then if you happen to fall within a certain range of MATLAB versions (if I recall Jan Simon knows which they are), then even though the field names generated will not actually be valid field names, you will be able to access them. You might need a bit of mex code to do that, though (Jan has posted it if I recall correctly.)
If your MATLAB version is new enough, then my understanding is that it will not allow you to load these non-standard .mat files. But perhaps some mechanism has been found since I last heard.

James Tursa
James Tursa on 26 Oct 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!