matlab listbox列表隐藏,listbox如何实现某行隐藏

找到解决方法了,使用求交集函数,intersect

更多集合运算符使用方法:

集合(set)运算符

1、c=union(a,b)集合并

2、c=intersect(a,b)  交集

3、setdiff (a,b)集合差

4、setxor(a,b)集合异或

规则是:a+b-(ab的公共元素)

等价于setdiff(union(a,b),intersect(a,b))

5、ismember(元素,集合)  集合的成员 (属于或in)

6、issorted(a)判断元素是否按序排列(只能是升序)

如为降序,可以变换为issorted(c(end:-1:1))

7、unique(a)删除集合中的重复元素

多个相同元素只取一个(取第一个)

(可以有多组相同的值,如多个1,多个2,多个3……)

集合运算符

union(a,b) union(a,b,’rows’)集合并

intersect(a,b)  交集

setdiff (a,b) setdiff(a,b,’rows’)向量的集合差

setxor(a,b) setxor(a,b,’rows’)集合异或

ismember(a,s) ismember(a,s,’rows’)集合的成员

issorted(a) issorted(a,’rows’)判断几何元素是否按序排列

unique(a) unique(a,’rows’)删除集合中的重复元素

一、union

union(a,b) union(a,b,’rows’)集合并

c = union(A, B)

c = union(A, B, 'rows')

[c, ia, ib] = union(...)

c = union(A, B, 'rows') when A and B are matrices with the same number of columns returns the combined rows from A and B with no repetitions.

二、intersect交集

c = intersect(A,B)

c = intersect(A,B,'rows')

[c,ia,ib] = intersect(...)

如不加’rows’,则a,b必须为两个向量;如为矩阵则必须加上rows此参数且必须列数相同(等宽),结果为两个矩阵中完全相同的行

c = intersect(A,B,'rows') when A and B are matrices with the same number of columns returns the rows common to both A and

A = [1 2 3 6]; B = [1 2 3 4 6 10 20];

[c,ia,ib] = intersect(A,B);

disp([c;ia;ib])

1     2     3     6

1     2     3     4

1     2     3     5

>> a=[1,2,3;4,5,6;7,8,9;10,11,12]

a =

1     2     3

4     5     6

7     8     9

10    11    12

>> b=[1,2,3;10,15,20;7,8,9;20,30,40;4,5,6]

b =

1     2     3

10    15    20

7     8     9

20    30    40

4     5     6

>> c=intersect(a,b)

??? Error using ==> intersect

A and B must be vectors, or 'rows' must be specified.

>> c=intersect(a,b,'rows')

c =

1     2     3

4     5     6

7     8     9

>> [c,ia,ib]=intersect(a,b,'rows')

c =

1     2     3

4     5     6

7     8     9

ia =   行号

1

2

3

ib =行号

1

5

3

三、setdiff

setdiff (a,b) setdiff(a,b,’rows’)向量的集合差

c = setdiff(A, B)

c = setdiff(A, B, 'rows')

[c, i] = setdiff(...)

四、setxor(a,b)

setxor(a,b) setxor(a,b,’rows’)集合异或

规则是:a+b-(ab的公共元素)

c = setxor(A, B)

c = setxor(A, B, 'rows')

[c, ia, ib] = setxor(...)

c = setxor(A, B) returns the values that are not in the intersection of A and B. The resulting vector is sorted. A and B can be cell arrays of strings.

c = setxor(A, B, 'rows'), when A and B are matrices with the same number of columns, returns the rows that are not in the intersection of A and B.

[c, ia, ib] = setxor(...) also returns index vectors ia and ib such that c is a sorted combination of the elements c = a(ia) and c = b(ib) or, for row combinations, c = a(ia,:) and c = b(ib,:)

a = [-1 0 1 Inf -Inf NaN];

b = [-2 pi 0 Inf];

c = setxor(a, b)

c =

-Inf   -2.0000   -1.0000    1.0000    3.1416       NaN

五、ismember

tf = ismember(A, S)

tf = ismember(A, S, 'rows')

[tf, loc] = ismember(A, S, ...)

A为元素,S为一个大的集合

tf = ismember(A, S, 'rows'), when A and S are matrices with the same number of columns, returns a vector containing 1 where the rows of A are also rows of S and 0 otherwise. You cannot use this syntax if A or S is a cell array of strings.

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

六、issorted

issorted(a) issorted(a,’rows’)判断几何元素是否按序排列(只能是升序)

tf = issorted(A)

tf = issorted(A, 'rows')

tf = issorted(A, 'rows') returns logical 1 (true) if the rows of two-dimensional matrix A are in sorted order, and logical 0 (false) otherwise. Matrix A is considered to be sorted if A and the output of sortrows(A) are equal.

A = [5 12 33 39 78 90 95 107 128 131];

issorted(A)

ans =

1

A = magic(5)

A =

17    24     1     8    15

23     5     7    14    16

4     6    13    20    22

10    12    19    21     3

11    18    25     2     9

issorted(A, 'rows')

ans =

0

B = sortrows(A)

B =

4     6    13    20    22

10    12    19    21     3

11    18    25     2     9

17    24     1     8    15

23     5     7    14    16

issorted(B)

ans =

1

七、unique

unique(a) unique(a,’rows’)删除集合中的重复元素

b = unique(A)

b = unique(A, 'rows')

[b, m, n] = unique(...)

多个相同元素只取一个(取第一个)

b = unique(A) returns the same values as in A but with no repetitions. The resulting vector is sorted in ascending order. A can be a cell array of strings.

b = unique(A, 'rows') returns the unique rows of A.

[b, m, n] = unique(...) also returns index vectors m and n such that b = A(m) and A = b(n). Each element of m is the greatest subscript such that b = A(m). For row combinations, b = A(m,:) and A = b(n,:).

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, m, n] = unique(A)

b =

1    2    3    4    5    6    8    9

m =

2   11    7   12    3   10    9    8

n =

1    1    5    6    2    3    3    8    7    6    2    4

A(m)

ans =

1    2    3    4    5    6    8    9

b(n)

ans =

1    1    5    6    2    3    3    9    8    6    2    4

Because NaNs are not equal to each other, unique treats them as unique elements. unique([1 1 NaN NaN])

ans =

1 NaN NaN

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值