Why two variables loading the same .mat file are not equal ?
Mostrar comentarios más antiguos
Hi,
I found something weird today and couldn't find an explanation on the forum.
When I load the same matlab file twice, and try to check if they are equal, the output is False.
In my situation, a and b are structures with large arrays inside, and I manually checked that they are actually equal.
Where does this come from ? Is there another way to quickly check the equality ?
Thanks !
a = load('myFile.mat')
b = load('myFile.mat')
isequal(a,b)
ans =
logical
0
3 comentarios
Matt J
el 17 de Feb. de 2022
Can you attach the .mat file?
Florian Bidaud
el 17 de Feb. de 2022
Editada: Florian Bidaud
el 17 de Feb. de 2022
Image Analyst
el 17 de Feb. de 2022
Can you at least show us a screenshot of you doing those 3 lines of code? And have both the code in the editor window, and the command window below in the picture. We need to make sure that they are both exactly the same filename, and not different somehow (like one ends in a space or something).
Respuesta aceptada
Más respuestas (2)
Walter Roberson
el 17 de Feb. de 2022
1 voto
You can get results that are not isequal() when you load data that does not serialize exactly.
Consider for example if you save a graphics object, then when you load() it is going to create two different versions of the graphics object.
Florian Bidaud
el 17 de Feb. de 2022
0 votos
3 comentarios
Image Analyst
el 17 de Feb. de 2022
OK, but the really bizarre thing that I just can't figure out is that you were reading the VERY SAME FILE, just twice: 'myFile.mat'
a = load('myFile.mat')
b = load('myFile.mat')
isequal(a,b)
I have no explanation for why it would show false. Does anyone?
Florian Bidaud
el 17 de Feb. de 2022
Rik
el 17 de Feb. de 2022
And Walter added another explanation: if the mat file contains a graphics object the second load might create a new object, instead of remembering that it has already that object in memory.
Categorías
Más información sobre Data Type Identification en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

