Why does comparison tool show modification when the values look the same?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I'm comparing two .mat files, each containing a 2D matrix (2416 x 843) which should be identical. The left one is generated by a MATLAB script and weighs 585 KB. The right one by a Python script and weighs 550 KB. The MATLAB comparison tool highlights some values (including all NaNs, by the looks of it) as modified, though they appear to be the same (see screenshot). This only seems to happen above a certain volume of data (each value in this matrix represents the average of 9 values; the issue does not occur for averages of 8 values or fewer). This does not happen with any other files/variables in this workflow.
Does anyone have any ideas why this might be happening?
Edit to add: I have also tried loading these two variables in the command window and compare them in a few different ways (examples below), all of which seem to suggest that MATLAB identifies them as equal.
>> sum(meanSampleAge - py_meanSampleAge, "all", "omitnan")
ans =
0
>> py_meanSampleAge(1642, 550) == meanSampleAge(1642, 550) % highlighted cell in the image above, same for others
ans =
logical
1
0 comentarios
Respuestas (2)
Taylor
el 18 de Abr. de 2024
It could be a data type issue. Double check what data type Python is saving as (MATLAB defaults to double precision). Here is an example of how sneaky data precision issues can be.
Pi is equal to pi of course
pi == pi
But what if we use different precisions of pi?
double(pi) == single(pi)
Well let's just convert that single-precision pi back to double
double(pi) == double(single(pi))
So if your data is saved by Python as single and MATLAB tries to automatically convert it to double, they values may still not show up as "equal".
4 comentarios
Taylor
el 19 de Abr. de 2024
Interesting. I'm hoenstly not entirely sure what is happening here. The NaNs being highlighted makes sense because NaNs are undefined values.
nan == nan
nan ~= nan
This is why isequaln exists. I'm not sure why the numeric values are being identified as not equal/modified. You could do more digging by inspecting the values at a specific index of the two matrices. You could also look at passing the data directly from Python to MATLAB using the MATLAB Engine in Python.
Ver también
Categorías
Más información sobre Call Python from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!