您的位置:首页 > 编程语言 > MATLAB

Matlab: 新学到的函数

2016-07-13 15:08 155 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: