Reading all variable from a mat file.

5 views (last 30 days)
Arun
Arun on 25 Oct 2013
Commented: James Tursa on 31 Oct 2013
Hi
I am experiencing a some trouble reading data from a mat file. The file is created by a SW made by Agilent, which is to log data from a digital multi meter.
This SW makes it possible to save data in mat-format, which I did.
When I load the mat file in matlab I cannot get all the data. But when I look at the variable content in the view'er, I get the image shown below
When I use "whos" to find out about the content of the file. It seems like it finds all seven variable called "Data". The result from whos is shown below
When I use load function to read mat files I get only the last variable called "Data".
1. had an impression that it was not possible to have variables with the same name, how come this is possible?
2. How do I get the values from all "Data" variables
br Arun
  5 Comments
Image Analyst
Image Analyst on 30 Oct 2013
How did you get t? Didn't you do something like
t = load(yourMatFileName);
whos t
Then t should have all the data, like you showed, where each structure in the t structure array contains one version of data. So t(1).Data = the first data array, t(2).Data = the second array, or something like that.
James Tursa
James Tursa on 31 Oct 2013
@Image Analyst: I believe Arun is getting the above information with the whos function and with the variable viewer ... he isn't actually loading any of these variables to get that "header" information. It is when he does attempt to load them that they end up overwriting each other and he ends up with only the last one.

Sign in to comment.

Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 25 Oct 2013
Edited: Azzi Abdelmalek on 25 Oct 2013
How can you have multiple variables with the same name? one name, one variable
a=10;
a=20% will erase the first content of a
  1 Comment
Arun
Arun on 29 Oct 2013
Hi
That was exactly my point in the first question. The mat file is created from a third party SW, therefore I do not have insight on how the mat file is created.
br

Sign in to comment.


James Tursa
James Tursa on 30 Oct 2013
Edited: James Tursa on 30 Oct 2013
The new version of LOADFIXNAMES is now available on the FEX. You can find it here:
It will load all of the variables it finds in the mat file and change any duplicate names to avoid name clashes. So your Data, Data, Data, etc variable names will get loaded as Data, Data00002, Data00003, etc. This new version has undergone only a limited amount of testing but it appears to be working as expected. Let me know if you have any problems.
While I was in the code I went ahead and added the capability to return a struct as an output instead of loading variables directly itno the workspace (just like the regular LOAD function allows).
You might consider contacting Agilent to let them know that their s/w is creating an invalid mat file with duplicate names.

Community Treasure Hunt

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

Start Hunting!