赞
踩
1. intersect(A,B):集合交集
A = [1 2 3 6]; B = [1 2 3 4 6 10 20];
>> c = intersect(A,B)
c =
1 2 3 6
2. ismember :是否是集合中的元素
[tf, loc] = ismember(A, S, ...)
set = [0 2 4 6 8 10 12 14 16 18 20];
a = reshape(1:5, [5 1])
a =
1
2
3
4
5
ismember(a, set)
ans =
0
1
0
1
0
set = [5 2 4 2 8 10 12 2 16 18 20 3];
[tf, index] = ismember(a, set);
index
index =
0
8
12
3
1
3. issorted:判断集合是否排序 (相关函数,sort:排序)
A = [5 12 33 39 78 90 95 107 128 131];
issorted(A)
ans =
1
4. setdiff :集合差集
>> A=[1 2 3 4 5];
>> B=[0 1 5 7 2];
>> E = setdiff(A, B) %求集合差A-B
E =
3 4
A = magic(5);
B = magic(4);
[c, i] = setdiff(A(:), B(:));
c' = 17 18 19 20 21 22 23 24 25
i' = 1 10 14 18 19 23 2 6 15
5. setxor :集合异或(不在交集中的元素)
>> A=[1 2 3 4 5];
>> B=[0 1 5 7 2];
F = setxor(A, B)%求A与B交集的补集
F =
0 3 4 7
6. union :两个集合的并
7. unique :返回向量作为一个集合所有元素(去掉相同元素)
A = [1 1 5 6 2 3 3 9 8 6 2 4]
A =
1 1 5 6 2 3 3 9 8 6 2 4
b = unique(A)
b =
1 2 3 4 5 6 8 9
8. cat(d,A,B): 把数组A和B按指定的维数d连接起来
A = B =
1 2 5 6
3 4 7 8
>> cat(1,A,B)
ans =
1 2
3 4
5 6
7 8
>> cat(2,A,B)
ans =
1 2 5 6
3 4 7 8
>> cat(3,A,B)
ans(:,:,1) =
1 2
3 4
ans(:,:,2) =
5 6
7 8
9. sort(A):将数组A中的元素按升序排列
A = [ 3 7 5
0 4 2 ];
sort(A,1) :列排序
ans =
0 4 2
3 7 5
sort(A,2) :行排序
ans =
3 5 7
0 2 4
10. strvcat: 竖向组合
t1 = 'first'; t2 = 'string'; t3 = 'matrix'; t4 = 'second';
S1 = strvcat(t1, t2, t3) S2 = strvcat(t4, t2, t3)
S1 = S2 =
first second
string string
matrix matrix
S3 = strvcat(S1, S2)
S3 =
first
string
matrix
second
string
matrix
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。