Reading all variable from a mat file.

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 comentarios

James Tursa
James Tursa el 25 de Oct. de 2013
Editada: James Tursa el 25 de Oct. de 2013
That's an invalid MAT file, but you still have to deal with it. I can probably modify my FEX submission to do this without too much effort:
This submission is a C-mex routine. Are you running a 32-bit MATLAB version or 64-bit MATLAB version? The 32-bit version comes with a C compiler, but the 64-bit version doesn't.
Would placing them into variable names such as Data_01, Data_02, etc be sufficient? I can probably get something like that working this weekend and uploaded next week.
Arun
Arun el 29 de Oct. de 2013
Hi
Thank you very much for the hint.
I will run through the script you have made by this week and let you know if I was successful in renaming the variables or if I have some questions.
br
James Tursa
James Tursa el 29 de Oct. de 2013
I finished the code last night and will try to test it today or tomorrow. If everything looks OK, I will upload it by tomorrow.
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 el 31 de Oct. de 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.

Iniciar sesión para comentar.

Respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 25 de Oct. de 2013
Editada: Azzi Abdelmalek el 25 de Oct. de 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 comentario

Arun
Arun el 29 de Oct. de 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

Iniciar sesión para comentar.

James Tursa
James Tursa el 30 de Oct. de 2013
Editada: James Tursa el 30 de Oct. de 2013

0 votos

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.

Categorías

Preguntada:

el 25 de Oct. de 2013

Comentada:

el 31 de Oct. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by