一些常用函数

1.cumsum--------------------累加求和函数

cumsum(A,2)表示返回每行的累加和

  EX:

A =
     1     2     3
     2     3     4
>> cumsum(A,2)
ans =
     1     3     6
     2     5     9
>>cumsum(A)
ans =
     1     2     3
     3     5     7

 

2.ismember

Lia = ismember(A,B) returns an array containing logical 1 (true) where the data in A is found in B. Elsewhere, the array contains logical 0 (false).

  • If A and B are tables or timetables, then ismember returns a logical value for each row. For timetables, ismember takes row times into account to determine equality. The output, Lia, is a column vector.

大概意思就是查看数组A中的元素是否能再数组B中找到,可以则返回1

 

3.num2str(大多数用于绘制图形)

s = num2str(A) converts a numeric array into a character array that represents the numbers. The output format depends on the magnitudes of the original values.num2str is useful for labeling and titling plots with numeric values.

  将数字转换为字符串

 

4.text

text(x,y,txt) adds a text description to one or more data points in the current axes using the text specified by txt. To add text to one point, specify x and y as scalars in data units. To add text to multiple points, specify x and y as vectors with equal length.

其中 x,y分别表示横纵坐标,进行文本标注

 

5.randperm(random permutation)

p = randperm(n) returns a row vector containing a random permutation of the integers from 1 to n inclusive.

p = randperm(n,k) returns a row vector containing k unique integers selected randomly from 1 to n inclusive.

随机排列函数,1---n的整数随机排列,k则表示整数的数量

 

6. giobal 

Declare variables as global   定义全局变量

7. meshgrid

[x,y]=meshgrid(x,y) 基于向量x和y中包含的坐标返回二维网格坐标

 

9.pdist和squareform的组合使用

这两个函数组合可求解两两距离的矩阵

例:

a=rand(3)

d=pdist(a)

D=squareform(d)

a =
    0.8147    0.3427    0.5619
    0.3249    0.3757    0.3958
    0.2462    0.5466    0.3981

 d=0.5183    0.6257    0.1881

D =
         0    0.5183    0.6257
    0.5183         0    0.1881
    0.6257    0.1881         0
posted @ 2020-04-21 17:02  fuxisong_97  阅读(176)  评论(0)    收藏  举报