如何使用Matlab在矩阵中查找唯一的(非重复的)值 [英] How to find a unique (non-repeated) value in a matrix by using matlab
本文介绍了如何使用Matlab在矩阵中查找唯一的(非重复的)值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每个人.假设我有以下(3x3)矩阵A:
everyone. Let's say I have following (3x3)matrix A:
0 1 3
0 0 3
0 0 0
我的问题是如何通过使用matlab找出矩阵中的唯一值? 在这种情况下,结果应为1. 我尝试过使用
My question is how to find out the unique value in that matrix by using matlab? In this case, the result should be 1. I have tried used the
value=unique(A)
但是它返回的向量不是我想要的{0; 1; 3}.
but it returned a vector {0;1;3} is not what I want.
非常感谢你们能帮助我解决这个问题.谢谢!
I much appreciate if you guys can help me solve this problem. Thank you!
推荐答案
这里很短
value = A(sum(bsxfun(@eq, A(:), A(:).'))==1);
它比较矩阵中的所有成对元素,并计算它们相等的次数,并返回仅计数一次的元素.
It compares all pairs of elements in the matrix and counts how many times they are equal and returns the ones that have been counted only once.
这篇关于如何使用Matlab在矩阵中查找唯一的(非重复的)值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文