11.8 Matlab 学习相关的函数功能

(1).集合的函数

intersect:取交集,http://www.matkk.com/intersect.html
unique:取各自独立的部分,http://www.matkk.com/unique.html
union:取并集(当然,去了冗余),http://www.matkk.com/union.html

intersect

Matlab中集合的交运算函数intersect

intersect
Set intersection of two vectors

Syntax

c = intersect(A,B)
c = intersect(A,B,'rows')
[c,ia,ib] = intersect(...)

Description

c = intersect(A,B)
returns the values common to both A and B. The resulting vector is sorted in ascending order. In set theoretic terms, this is A B. A and B can be cell arrays of strings.

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 B.

[c,ia,ib] = intersect(a,b)
also returns column index vectors ia and ib such that c = a(ia) and c = b(ib) (or c = a(ia,:) and c = b(ib,:)).

Examples

  1. A = [1 2 3 6]; B = [1 2 3 4 6 10 20];
  2. [c,ia,ib] = intersect(A,B)
  3. disp([c;ia;ib]);

            6
                 4
                 5


(2) rect 鼠标选框的函数

Syntax

rect = getrect
rect = getrect(fig)
rect = getrect(ax)

Description

rect = getrect lets you select a rectangle in the current axes using the mouse. Use the mouse to click and drag the desired rectangle.rect is a four-element vector with the form[xmin ymin width height]. To constrain the rectangle to be a square, use a shift- or right-click to begin the drag.

rect = getrect(fig) lets you select a rectangle in the current axes of figurefig using the mouse.

rect = getrect(ax) lets you select a rectangle in the axes specified by the handleax.

Examples

Select a rectangle in an image of the moon:

imshow('moon.tif')
rect = getrect

(3)正态分布  matlab  并不简单

randn() 是标准正态分布
normrnd是自己可以指定均数和标准差的正太分布。


rand('state',1);  每次的随机的状态都会是一致的。

(4)matlab中sub2ind函数

sub2ind返回值就是这个元素在这个矩阵中的索引值。

>> A = [1 2 3; 4 5 6];

>> b=sub2ind(size(A),2,2)

b =

     4


第一个参数size(A)是A的维数,对应几维后面就跟几个参数,这里是二维数组(在MATLAB中,一个空矩阵[]、一个数、一个向量都是二维的)

另外我们可以发现矩阵是从列开始的sub2ind2(size(a),2,2)第二行第二个元素对应位置是5,说明先从第一列开始然后再是第二列的矩阵的索引值是2+2=4;


(5)网格函数

[x,y] = meshgrid(-4:.5:4); 


(6)分割函数

以下面这样一串字符为例

Hello Nocturne Studio

首先去除首尾的多余空格:
str = deblank(str)

例1:设这几个字符串是以制表符分隔的,可以这样来做:
S = regexp(str, '\t', 'split')

例2:设这些字符串是以一个或多个空格分隔的,可以用正则表达式来描述:
S = regexp(str, '\s+', 'split')

这样,S(1)=’Hello’,S(2)=’Nocturne’,S(3)=’Studio’。

注意,上面得到的结果S是一个cell型变量,它的每个元素比如S(1)仍然是cell型的,只能用来display,不能直接用来进行字符串操作(比如获取其中的某个字符),所以我们在使用需要执行一次:
s1 = char(S(1))

这样的s1才是一个真正的字符串,可以进行后续的操作。


Sub_order= regexp(data_dirname, '\.', 'split');

% . 分隔字符串
Sub_order_name=char(Sub_order(1));
choose_picture=str2num(Sub_order_name);


(7)matlab 删除一列(3)的方法

a=a(:,[1,2,4,5]);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值