I have created a sparse matrix using MEX and also created a sparse matrix using MATLAB. To fill in the values of the matrix i have used same formula.
Now to check if the both the matrices are equal I used result=(A==B). result returns 1 for all indices, which implies that all the matrix elements are equal.
But if I do find(A-B) it returns some indices, which indicates that at these indices the values are non-zero. How is this possible?
Note: When i compare the value at these indices it shows equal !
I’m guessing you have values of infinity cropping up in your matrices at the same points. For example:
The discrepancy here results from the fact that certain operations involving infinity result in
NaNvalues. You can check to see if you have any infinities inAandBby using the function ISINF like so:And if you get a value of 1 (i.e. true), then the presence of infinities is likely the source of your discrepancy.