一些常用函数
1.cumsum--------------------累加求和函数
cumsum(A,2)表示返回每行的累加和
EX:
2 3 4
2 5 9
3 5 7
2.ismember
returns an array containing logical Lia = ismember(A,B)1 (true) where the data in A is found in B. Elsewhere, the array contains logical 0 (false).
-
If
AandBare tables or timetables, thenismemberreturns a logical value for each row. For timetables,ismembertakes row times into account to determine equality. The output,Lia, is a column vector.
大概意思就是查看数组A中的元素是否能再数组B中找到,可以则返回1
3.num2str(大多数用于绘制图形)
converts a numeric array into a character array that represents the numbers. The output format depends on the magnitudes of the original values.s = num2str(A)num2str is useful for labeling and titling plots with numeric values.
将数字转换为字符串
4.text
text( adds a text description to one or more data points in the current axes using the text specified by x,y,txt)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)
0.3249 0.3757 0.3958
0.2462 0.5466 0.3981
d=0.5183 0.6257 0.1881
0.5183 0 0.1881
0.6257 0.1881 0

浙公网安备 33010602011771号