两个矩阵的高效比较 MATLAB
有没有一种方法可以有效地比较两个矩阵,我在想类似
same = abs((AB)) = 0...
将一个矩阵的值减去另一个矩阵的值,如果结果为 0,则它们是相同的,还有一个 isequal() 函数,比较两个矩阵的最佳方法是什么?
Is there a way to efficiently compare two matrices, I was thinking something like
same = abs((A-B)) = 0...
substracting values of one matrix to the other and if they result is 0, they are the same, also there is a isequal()
function, What would be the best to compare both matrices?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您只需执行
isequal(A,B)
即可,如果 true 则返回1
,如果 false 则返回0
。You can simply do
isequal(A,B)
and it will return1
if true or0
if false.由于您正在处理浮点,因此您可能不想测试精确的相等性(取决于您的应用程序)。因此,您只需检查它
是否足够小,例如
< 1e-9
,同样取决于您的应用程序。这是矩阵 2-范数,如果 A - B 是全零矩阵或接近零矩阵,则该矩阵将接近零。Since you're dealing with floating point, you probably don't want to test for exact equality (depending on your application). Thus, you can just check that
is sufficiently small, say
< 1e-9
, again depending on your application. This is the matrix 2-norm, which will be near zero ifA - B
is the all zeros matrix or nearly so.似乎 ISEQUAL 比检查减法后的非零元素更快:
It seems that ISEQUAL is faster than checking for non-zero elements after subtraction: