Missing elements in .mat while using load with r2017a

I work with an other software for data acquisition which can export to a Matlab file version 7.3. When i use load('filename') with Matlab 2017a all the datas from the acquisition are missing whereas this load seems to work with Matlab 2015, 2013 and 2010.
How do i get back my data with R2017a without using an other version ? What changed ?

 Respuesta aceptada

Jan
Jan el 28 de Jul. de 2017
Editada: Jan el 28 de Jul. de 2017
This is not a -v7.3 MAT file, but a 5.0 MAT-file version.
You cannot open it in 2017a, because it contains the field name 'Numéro_de_l_essai', while Matlab accepts ASCII characters only. You should see a corresponding error message - for the older Matlab versions also:
Error using load
Invalid field name: 'Numéro_de_l_essai'.
I will fix this file for you and post it later.
[EDITED] Phew, this is not trivial. The MAT file contains several strange and evenm duplicate names. The tool from the FileExchange replies different outputs when it runs repeatedly.
You should fix the program, which creates the files, instead of tinkering the files. This is neither a -v7.3 file nor can I imagine that you did not get a corresponding error message.

13 comentarios

Lise Dubroca
Lise Dubroca el 31 de Jul. de 2017
Editada: Lise Dubroca el 31 de Jul. de 2017
In fact i dont have any error message, and for older version the matfile works perfectly fine (at least for 2010a and 2015). I link the screen shots. In the software i can choose between a v5.0 or a v7.3 when i export the data, and i do choose v7.3.
So, if i understand, the problem may come from the software ?
EDIT : And if i manage to modify my file at his creation, changing the names into ASCII characters, do you think this would bring back my datas ? (Sorry if i dont try it first, in fact, this is not easy at all to do)
Jan
Jan el 31 de Jul. de 2017
The data are valid and existing in the file. If you cannot recreate them with ASCII names in the MAT file, you can use loadfixnames from the FileExchange to obtain the data. Unfortunately it does not replace the names correctly, but you can import the data and obtain the data by struct2cell. Then you can re-create a struct with ASCII names manually. But if you want to do this for 100 files, this procedure will be too prone to errors.
The screenshots are not from 2010a and 2015, but you can import the data with invalid names in R2017a obviously. This is strange. If you state, that it works "perfectly fine" in older Matlab version, how do you access the data after the import? Non ASCII characters in names of variables should cause errors.
Jan
Jan el 31 de Jul. de 2017
I don't get it. In the original question you wrote "Matlab 2017a all the datas from the acquisition are missing". The screenshot shows, that all variables are imported from the file in R2017a, although I expect, that they should be rejected with an error message, as they are in R2016b.
Lise Dubroca
Lise Dubroca el 1 de Ag. de 2017
Editada: Lise Dubroca el 1 de Ag. de 2017
When i say that these datas (from the acquisiton) are missing, it means that Data1_Time and Data1_X1 are missing. They are missing in 2017a and they are not missing in Matlab with 2010a (or 2015 but i dont have the computer anymore, so i dont have screenshots with 2015).
The other variables, including the non-ASCII characters are only the settings of my acquisiton, that i don't use since they are always the same.
@Jan,
In R2017a, when using plain load, there's no error message. No idea if the whole file is loaded, but matlab does create some variables with invalid names (such as Numéro_de_l_essai). They're completely inaccessible though (even with eval) and it messes up tab completion even for the valid variable names.
On the other hand, loading into a structure by providing an output to load fails with an Invalid field name: 'Numéro_de_l_essai' error.
@Lise, the most important point is that your mat file is not a valid mat file. If it worked properly in previous it was pure luck, and it is very possible that something sometimes may not have loaded properly and you did not notice. So, really at this point you should be fixing the program that generates these files.
Even if today you managed to load correctly this invalid file into matlab, there's no guarantee that it would work, and it may break in some subtle way that you may not notice (e.g. some vector has one less element, or some values get swapped) but would be catastrophic for you.
Jan
Jan el 1 de Ag. de 2017
@Guillaume: This is surprising. The import of MAT files with invalid names has been rejected since 2009a (as far as I remember) and until 2016b. And now it is accepted again? Formerly you could access varaibels with malformed names using mexGetVariable and mexPutVariable from a MEX function, but this did not work also since 2009a. But in the MEX level you can import the file to a struct and you have full access to the field names. I'd write a C-code, which imports MAT files to cells, such that bad fieldnames does not cause any troubles. But on one hand James' tool works almost perfect (I assume a small bug due to 64 bit addressing), and the recursive fixing of substructs is a kind of tedious in C.
More testing:
In R2016a and R2016b, the file is also loaded with no error message or warning using plain load. However, the invalid variable names are not created. In R2017a, they are.
In all versions, there is no Data... variable loaded. I would suspect it's not in the file.
More testing :
I can also import the same datas in .xls (this file is a test, i have 60 more variables instead of 2 when i work) and and the results are the same when i use xlsread now and when i used load with R2015. So the load of my datas in 2015, and i presume in 2010 does work, without missing values etc. The bug may be due to 9.xx version of Matlab.
Do you know what changed ? Why is this only pure luck since it seems to work for, in fact, most versions of Matlab ?
James Tursa
James Tursa el 1 de Ag. de 2017
Editada: James Tursa el 1 de Ag. de 2017
Apologies! I have no explanation for how this occurred or how I could have uploaded the mex routine with this bug in it, but this line in the loadfixnames.c file:
while( !(*target++ = *source++) ) {
should be this instead:
while( (*target++ = *source++) ) {
It was meant to be a simple string copy. My only thought is that I know at some point I couldn't create invalid mat files to test with because the mat file writing API functions became too smart to let me. So this code was uploaded as only partially tested. In any event, that line above is simply a string copy and of course with that ! in there it wasn't doing that.
I will need to upload a fix to the FEX soon, and maybe at the same time make some smarter choices for valid replacement characters for those upper ASCII characters instead of always using underscore.
Sorry about that!
Jan
Jan el 1 de Ag. de 2017
@James: There is no reason for apologies. Thanks for sharing this function, which helped me to inspect the contents of the ugly MAT file!
Maybe the undocumented function mxIsValidMatName is useful. I though of creating cell arrays with the data and the names, such that the renaming can happen in Matlab, where it is more convenient.
James Tursa
James Tursa el 1 de Ag. de 2017
Editada: James Tursa el 1 de Ag. de 2017
New version is uploaded. Seems to work on my 32-bit MATLAB. Can you try it out on your 64-bit MATLAB?
Even if my variables are ASCII it doesnt work. But i can export only the variables with Data1_..., and it works ! I have them all, even with my bigger files.
Thank you all for your help !
Does it work if you assign the output to a variable? E.g.,
s = loadfixnames('Test');
If so, maybe it is the mexPutVariableSharedDataCopy routine that is broken in versions of MATLAB that I can't test. You could try replacing the call to that routine with a call to the official function mexPutVariable instead.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Software Development en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 28 de Jul. de 2017

Comentada:

el 4 de Ag. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by