Comparing two matriced
1 次查看(过去 30 天)
显示 更早的评论
Hi,
Is there a fast way to compare the differences between two matrices with the same dimension:
example Assume A and B each is a 1000x1000 matrix. Is there a way to find where A and B differ in one step?
0 个评论
回答(4 个)
Jan
2011-3-10
And if the matrices are results of floating point computation a certian relative or absolute tolerance might be helpful:
abs_d = (A - B) < Tol
rel_d = ((A - B) ./ min(A, B)) < Tol
And now the same tools as replied by Walter, Sean and Matt can be applied.
0 个评论
Sean de Wolski
2011-3-10
The logical matric
ABne = A~=B
or if you need the indices
[r c] = find(ABne);
0 个评论
Matt Fig
2011-3-10
And a visual method:
spy(A~=B)
And a quick method to count the number of locations where A is not equal to B:
nnz(A~=B)
8 个评论
Jan
2011-3-10
NNZ is *much* faster in SSE, especially if the data are aligned at 128 bit boundaries.
Sean de Wolski
2011-3-10
I find it funny how the help for nnz says:
The density of a sparse matrix S is nnz(S)/prod(size(S))"
But M-Lint now says:
numel(S) is faster than prod(size(S))"
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!