常用的加减乘除运算
5+6
ans = 11
...
%xxx 表示注释
逻辑运算中不等于是 ~=
矩阵
A = [1 2 3] 1*3的矩阵
B = [1,2;3,4;5,6] 3*2的矩阵
A(x,y)索引
size(A) : 返回的就是 1 3
size(B): 返回的就是 3 2
length(x):返回列、行中最大值
pwd:列出当前路径
cd '/xx/x': 切换目录
ls:列出当前目录所有文件
load xx :加载文件
who:当前所用到的变量
clear x:删除某个变量
clear:删除当前所有变量
save xxx y;保存到文件y到xxx
eye(n):生成单位矩阵N*N
ones(N):生成全部为1的N*N的矩阵
A(:,2)第二列的所有内容
A(2,:)第二行的所有内容
A([1,3],:)第一、三行的所有内容
A(:) 将所有的值变成一个列向量,从第一列加到最后一列
A =
1 2 100
3 4 101
5 6 102
A(:)
1
3
5
2
4
6
100
101
102
矩阵运算:A*B 矩阵相乘
A .* B :点乘
A.^2 : 平方运算
A': A的转置
magic:
octave:32> help magic
'magic' is a function from the file D:\Program\Octave-4.4.1\share\octave\4.4.1\m\special-matrix\magic.m
-- magic (N)
Create an N-by-N magic square.
A magic square is an arrangement of the integers '1:n^2' such that
the row sums, column sums, and diagonal sums are all equal to the
same value.
Note: N must be a scalar greater than or equal to 3. If you supply
N less than 3, magic returns either a nonmagic square, or else the
degenerate magic squares 1 and [].
Additional help for built-in functions and operators is
available in the online version of the manual. Use the command
'doc <topic>' to search the manual index.
prop:相乘
max:第一个维度的最大值
计算对角矩阵的和
a =
1 2 3
4 5 6
7 8 9
max(a*单位对角矩阵)
ans = sum(sum(a.*eye(3)));
plipud:矩阵行交换
plot(x,y) :画出y与x的函数
同时画出两个图像,hold on ,下一个绘图命令
legend显示直线标记
title:标记
print -dpng 'xxxx.png' 打印文件到当前的路径
subplot(x,y,index):划分为(x,y)格子,读取第index个
axis:(x_start,x_end,y_start,y_end): 改变图形刻度
A = magic(5)
clf:清除屏幕
imagesc(A),colorbar
addpath():search path