matlab 类的集合,MATLAB集合操作

MATLAB提供各种函数集合运算,如集,交集和测试组成员等。

下表显示了一些常用的设置操作:

函数

描述

intersect(A,B)

Set intersection of two arrays; returns the values common to both A and B. The values returned are in sorted order.

intersect(A,B,'rows')

Treats each row of A and each row of B as single entities and returns the rows common to both A and B. The rows of the returned matrix are in sorted order.

ismember(A,B)

Returns an array the same size as A, containing 1 (true) where the elements of A are found in B. Elsewhere, it returns 0 (false).

ismember(A,B,'rows')

Treats each row of A and each row of B as single entities and returns a vector containing 1 (true) where the rows of matrix A are also rows of B. Elsewhere, it returns 0 (false).

issorted(A)

Returns logical 1 (true) if the elements of A are in sorted order, and logical 0 (false) otherwise. Input A can be a vector or an N-by-1 or 1-by-N cell array of strings. A is considered to be sorted if A and the output of sort(A) are equal.

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.

setdiff(A,B)

Set difference of two arrays; returns the values in A that are not in B. The values in the returned array are in sorted order.

setdiff(A,B,'rows')

Treats each row of A and each row of B as single entities and returns the rows from A that are not in B. The rows of the returned matrix are in sorted order.

The 'rows' option does not support cell arrays.

setxor

Set exclusive OR of two arrays

union

Set union of two arrays

unique

Unique values in array

例子

创建一个脚本文件,并键入下面的代码:

a = [7 23 14 15 9 12 8 24 35]

b = [ 2 5 7 8 14 16 25 35 27]

u = union(a, b)

i = intersect(a, b)

s = setdiff(a, b)

当您运行该文件,它会产生以下结果:

a =

7 23 14 15 9 12 8 24 35

b =

2 5 7 8 14 16 25 35 27

u =

Columns 1 through 11

2 5 7 8 9 12 14 15 16 23 24

Columns 12 through 14

25 27 35

i =

7 8 14 35

s =

9 12 15 23 24

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值