Why two variables loading the same .mat file are not equal ?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Image Analyst
2022년 2월 17일
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).
채택된 답변
Rik
2022년 2월 17일
편집: Rik
2022년 2월 17일
I guess boldly:
There might be a NaN value hidden somewhere in your data:
isequal(NaN,NaN)
s1=struct('x',NaN);s2=s1;
isequal(s1,s2)
isequal(ComputeNonCryptHash(s1),ComputeNonCryptHash(s2))
추가 답변 (2개)
Walter Roberson
2022년 2월 17일
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.
댓글 수: 0
Florian Bidaud
2022년 2월 17일
댓글 수: 3
Rik
2022년 2월 17일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!