unique
>> A = [9 2 9 5];
>> [C, ia, ic] = unique(A)
%Find the unique values of A and the index vectors ia and ic, such that C = A(ia) and A = C(ic).
C =
2 5 9
ia =
2
4
1
ic =
3
1
3
2
ismember
>> A = [5 3 4 2];B = [2 4 4 4 6 8];
>> Lia = ismember(A,B)
%Determine which elements of A are also in B.
Lia =
0 0 1 1
find
>> X = [3 2 0; -5 0 7; 0 0 1]
X =
3 2 0
-5 0 7
0 0 1
>> [row,col,v] = find(X)
%Find the nonzero elements in a 3-by-3 matrix. Specify three outputs to return the row subscripts, column subscripts, and element values.
row =
1
2
1
2
3
col =
1
1
2
3
3
v =
3
-5
2
7
1
intersect
>> A = [7 1 7 7 4]; B = [7 0 4 4 0 5];
>> C = intersect(A,B)
%Find the values common to both A and B.
C =
4 7
本文通过MATLAB示例介绍了如何使用unique函数查找数组中的唯一值及其索引,使用ismember函数确定一个数组中的元素是否存在于另一个数组中,使用find函数定位矩阵中的非零元素位置,以及使用intersect函数找出两个数组的交集。
989

被折叠的 条评论
为什么被折叠?



