Matlab函数

本文介绍了MATLAB中常用的数组操作函数如any()、all()、union()等,并详细解释了如何使用这些函数进行集合运算、查找最大值及重塑矩阵形状等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

any() 相当于或操作,只要有1,就返回1

 

all() 相当于与操作,只要有0,就返回0

 

 

 

 C = union(A,B):

 

 C为A和B的并集。去掉相同元素。

 

C = intersect(A,B)

 

C为A和B的交集. The values of C are in sorted order.

 

 

 

[Lia,Locb] = ismember(A,B):

 

  判断A中元素是否为B中的子元素,如果不是则,Lia和Locb中元素值都为0(注意,Lia大小和A一样,Locb大小和B一样)。如果A中有元素是B中的,在Lia中对应返回值1,Locb, containing the highest index in B for each value in A that is a member of B. The output array, Locb, contains 0 wherever A is not a member of B.

 

[C,ia] = setdiff(A,B):

 

  返回的C元素为在A中出现,但是没有在B中出现,ia为其索引值,满足C = A(ia)。

 

 

 

D = D(:)'; % ensure that D is a row vector

 

D(:)按列将矩阵变为列向量

 

 

 

 

 

reshape是根据原来的矩阵创造新的矩阵,repmat是将原来的矩阵复制多次,构成一个大矩阵。

 

>> A=magic(4)

 

A =

 

16 2 3 13

5 11 10 8

9 7 6 12

4 14 15 1

 

B = reshape(A,...,[],...) calculates the length of the dimension represented by the placeholder [], such that the product of the dimensions equals prod(size(A)). The value of prod(size(A)) must be evenly divisible by the product of the specified dimensions. You can use only one occurrence of [].

 

>> reshape(A,[],2)

 

ans =

 

16 3

5 10

9 6

4 15

2 13

11 8

7 12

14 1

 

 

 

max(a),若a为向量,返回最大值,若a为矩阵,返回每列最大值作为一个向量。

 

C = max(A,B) returns an array the same size as A and B with the largest elements taken from A or B. The dimensions of A and B must match, or they may be scalar.

 

C = max(A,[],dim) returnsthe largest elements along the dimension of A specifiedby scalar dim. For example, max(A,[],1) producesthe maximum values along the first dimension of A.

 

[C,I] = max(...) finds the indices of the maximum values of A, and returns them in output vector I. If there are several identical maximum values, the index of the first one found is returned.

 

K>> c=magic(4)

 

c =

 

16 2 3 13

5 11 10 8

9 7 6 12

4 14 15 1

 

K>> max(c) 等同于max(c,[],1)

 

ans =

 

16 14 15 13

 

 

K>> max(c,[],2)

 

ans =

 

16

11

12

15

 

 

 

K>> [m,n]=max(c,[],2)

 

m =

 

16

11

12

15

 

 

n =

 

1

2

4

3

find; sparse;full

[i,j,s] = find(S);
[m,n] = size(S);
S = sparse(i,j,s,m,n);

对于稀疏矩阵,i,j分别是不为零项的index,s是其值

 


So does this, if the last row and column have nonzero entries:

[i,j,s] = find(S);
S = sparse(i,j,s);

 

 

转载于:https://www.cnblogs.com/huashiyiqike/p/3291078.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值