好久没更新了,正好学校要学MATLAB,就顺便更新一波吧,装作有人看的样子。
A = [1,2,3,4,5, 6]
A(5) = 5
A(2:4) = 2 3 4
A(1:2:6) = 1 3 5
A(4:end) = 4 5 6
A[1,4,6] = 1 4 6
a(31:end) = b
a = [1, 23, 43, 21, 45, 67]
b = [23, 1, 2]
c = [a,b]
>>c = [1, 23, 43, 21, 45, 67, 23, 1, 2]
d = a(1:2:6)
e = [b;d]
>>E = [23, 1, 2; 1, 43, 45]
#方法1
b = [A(1:10), A(21:27)]
#方法2
A[11,20] = []
a = [zeros(1,5), ones(1,5) .* 3]
x = [1, 2, 3]
y = [2, 5, 6]
x ./ y
>>[0.5, 0.4, 0.5]
x .\ y
>>[2.0, 2.5, 2.0]
#方法1
s0 = sqrt(54.6447^2 + 35.3553^2)
#方法2
v0 = [54.6447, -35.3553]
s0 = sqrt(sum(v0 .* v0))
A = randi([10,80],5,5)
P = rem(A,3)
A(P)
a = ones(4) .* 4.5
>>a =
4.5000 4.5000 4.5000 4.5000
4.5000 4.5000 4.5000 4.5000
4.5000 4.5000 4.5000 4.5000
4.5000 4.5000 4.5000 4.5000
A = rand(3,4)
A(2,3) = 0 #将第二行第三列的元素换为0
A(4,2) = 0 #添加第四行第二列元素为0,其他列默认为0
A(4,:) = [] #删除第四行
a = [1, 2, 3; 4, 5, 6; 7 ,8, 9]
b = a(1:2,:) #提取第一行到第二行所有元素
c = (:,2) #提取第二列的所有元素
A = rand(3,4)
A(2,2) = 0
B = A
B(3,1) = A(1,4)
B(1,4) = A(3,1)
>>A =
0.8530 0.5132 0.2399 0.2400
0.6221 0.4018 0.1233 0.4173
0.3510 0.0760 0.1839 0.0497
>>B =
0.8530 0.5132 0.2399 0.3510
0.6221 0 0.1233 0.4173
0.2400 0.0760 0.1839 0.0497
a = [1, 2, 3; 4, 5, 6; 7, 8, 9]
a'
>>ans =
1 4 7
2 5 8
3 6 9
矩阵行列式
a = [1, 2, 3; 4, 5, 6; 7, 8, 9]
det(a)
>>ans =
-9.5162e-16
矩阵的秩
B = rand(3)
>>B =
0.7317 0.5470 0.1890
0.6477 0.2963 0.6868
0.4509 0.7447 0.1835
rank(B)
>>ans =
3