inv
求逆矩阵
magic 魔方矩阵
索引矩阵里的元素,A(5),顺着列数第5个
save myfile.mat 保存数据
load myfile.mat 读入数据
To convert numeric values to characters, use functions,
such as num2str or int2str.
f = 71;
c = (f-32)/1.8;
tempText = ['Temperature is ',num2str(c),'C']
tempText =
Temperature is 21.6667C
三维画图
[X,Y] = meshgrid(-2:.2:2);
Z = X .* exp(-X.^2 - Y.^2);
Then, create a surface plot.
surf(X,Y,Z)
disp
1.输出字符串:
>>disp('my test')
my test
2.输出数字:
>> test=3;
>> disp(test)
3
3.同时输出字符串和数字:
>> test=3;
>> disp(['my
test=',num2str(test)])
my test=3
在循环中途输出,可以查看中间结果
mean 求均值
sum(A,n)表示将矩阵A沿着第n个维度求和
sum(A,2)如果A是二维矩阵,也就是按行求和
diag(A) 取出矩阵A中的对角元
diag(diag(X))
取出X矩阵的对角元,然后构建一个以X对角元为对角的对角矩阵
B = fliplr(A)
将矩阵A的列绕垂直轴进行左右翻转
如果A是一个行向量,fliplr(A)将A中元素的顺序进行翻转。
如果A是一个列向量,fliplr(A)还等于A
A = B(:,[1 3 2 4])
将B中的第3列和第2列换位置
fix 向零取整
zeros All
zeros
ones
All ones
rand
Uniformly distributed random elements
均匀分布
randn Normally
distributed random elements 正态分布
eye
产生单位矩阵
B=eye(3,5)
B =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
Floating-point numbers have a finite precision of roughly
16
significant decimal digits and a finite range of roughly
10-308 to 10+308
Numbers represented in the double format have a maximum
precision of 52 bits. Anydouble requiring more bits than 52 loses
some precision. For example, the following
codeshows two unequal values to be equal
because they are both truncated:
x = 36028797018963968;
y = 36028797018963972;
x == y
ans =1
/:右除。a/b表示矩阵a乘以矩阵b的逆。
\:左除。a\b表示矩阵a的逆乘以b
isfinite
返回一个与A维数相同的数组,如果A的元素为有限数,在对应位置返回逻辑1(真),若无限或为NaN,在对应位置返回逻辑0(假)。
对一个复数z,如果A的实部或者虚部有至少有一个是有限的,则isfinite(z)返回1,如果实部和虚部都是无限的或者NaN,则返回0
x = x(isfinite(x)) 去掉NaN和Inf
format short/short e/short g/long/long e/long
g/bank/+/rat/hex
If a statement does not fit on one line, use an ellipsis
(three periods), ..., followed
byReturn or Enter to indicate that the
statement continues on the next line
X = magic(4);
Then, to delete the second column of X, use
X(:,2) = []
This changes X to
X =
16 2 13
5 11 8
9 7 12
4 14 1
std 标准偏差
isprime 判断素数
find的返回值是,矩阵中为1的元素对应的下标索引
perms 排列函数
cell arrays 元胞矩阵
B={'jkghkfh',[1 25 4
8];eye(3),{'ddfsd','goodmarlab'}}
运行结果
B =
'jkghkfh'
[1x4
double]
[3x3 double]
{1x2 cell
}
C = {A sum(A) prod(prod(A))}
cell arrays contain copies of other arrays, not pointers
to those
arrays. If you subsequently change A, nothing happens to
C
Cell arrays can be used to store a sequence of matrices of
different sizes
B = prod(A)
将A矩阵不同维的元素的乘积返回到矩阵B
如果A是向量,prod(A)返回A向量的乘积。
如果A是矩阵,prod(A)将A看作列向量,返回每一列元素的乘积并组成一个行向量B。
如果A是多维数组,prod(A)沿着第一个非单例作为向量,返回一个行向量数组。
《Simulink与信号处理》
B = prod(A,dim)
沿着指定的dim标量的维计算A矩阵的乘积。注:dim=2表示沿行计算。
reshape
重新调整矩阵的行数、列数、维数
When creating a character
array, you must make each row of the array the same
length. (Pad the ends of the shorter
rows with spaces.) The char function does this padding for
you
s = 'Hello'
a = double(s) 转换成数
s=char(a)
转换成字符串
C = cellstr(S)
convert a padded character array to a cell array of character
vectors
S = char(C)
reverse the
process