当前位置:网站首页>Octave基本语法
Octave基本语法
2020-11-08 21:03:00 【Allez_Levide】
Octave基本函数
生成矩阵函数
- eye(n):生成n行n列的单位矩阵
- rand(n,m):随机生成n行m列大小范围在0~1之间的随机数
- randn(n,m):按高斯分布生成n行m列的随机数
- ones(n,m):生成n行m列元素均为1的矩阵
- zeros(n,m):生成n行m列元素均为0的矩阵
矩阵操作函数
- B = A(n:m):将矩阵A的第n行到第m行的值赋给矩阵B
- A(n,m):取n行m列元素
- A([1 3],: ):将矩阵A第一行与第三行的所有元素显示出来
- A(2,: ):将矩阵A第二行的所有元素显示出来
- A = [A,B]:将基础B扩展到矩阵A的右边,并将所得到的新矩阵重新赋给A
- A = [A;B]:将基础B扩展到矩阵A的下边,并将所得到的新矩阵重新赋给A
- A(: ):将A中的所有元素按照列的方向依次形成一个新的列向量
- reshape(A(i:j), n, m):A是一个列向量,i和j表示将列向量的第i项到第j项取出重组为另一个矩阵,n和m分别是重组后对应的行和列
矩阵运算
- a*b :矩阵相乘
- a.*b:每个元素相乘
- a.^2:对元素进行平方
- 1./a:对a的元素求倒数
- log(a):求对数
- exp(a):以e为底,以a为幂
- abs(a):求绝对值
- v+ones(length(v),1):对v的元素加1
- A’:A的转置
- prin(A):求逆或者伪逆
- sum(a):矩阵里的数据求和
- prod(a):乘积
- floor(a):向上取整
- ceil(a):向下取整
- max(A,[],1):取每一列的最大值
- max(A,[],2):取每一行的最大值
- max(max(A)):矩阵里的最大值
简单作图
- plot(x,y):以x为横坐标,y纵坐标做图,第三个参数可选,表示图像类型('r’颜色为红色)
- hold on:将多个图画在同一个图像中。用法:先画出plot(t,y1);然后出入hold on;然后在输入plot(t,y2),即可以实现两个图像同时显示
- xlabel(xString):xString表示x轴的名
- ylabel(yString):yString表示y轴的名
- legend(string1, string2…):按照作图顺序为每条曲线命名
- title(tString):tString表示图表名称
- print -dpng ‘file.png’:将图表保存为png图片
- close:将当前打开的图表关掉
- figure(n):使用plot函数前使用该函数,保证n不同,可以开启多个图表窗口而不会被覆盖
- subplot(1,2,1):将图纸分为1*2的网格,画图时使用第一个网格
- axis([x1,x2,y1,y2]):设置刻度值,[x1,x2]为横轴的刻度范围,[y1,y2]为纵轴的刻度范围
- imagesc(A):为矩阵A绘制一个彩图矩阵,不同的值对应着不同的颜色深度
常用操作
- PS1(">> “):将命令行前导符号改成”>> "
- size(A,[N]):A为一个矩阵,省略第一个参数时函数返回一个数组[n,m],其中n为A行数,m为A的列数;第二个参数可选,表示矩阵的维度,返回第N维的大小。例如
A = 1
2
3
4
5
6
7
8
9
size(A) = 9 1
size(A,1) = 9
size(A,2) = 1
- disp():打印变量或字符串
- pwd:显示当前路径
- load:加载数据文件
- who:查询工作区内的变量名称
- whos:查询工作区内的详细信息
- clear:清除某一变量(clear x),若clear后没有变量,则清除全部变量
- clc:清屏
- save file A:将A矩阵存储到文件file中
版权声明
本文为[Allez_Levide]所创,转载请带上原文链接,感谢
https://my.oschina.net/LevideGrowthHistory/blog/4708308
边栏推荐
- 使用Fastai开发和部署图像分类器应用
- 实验一作业
- Opencv solves the problem of ippicv download failure_ 2019_ lnx_ intel64_ general_ 20180723.tgz offline Download
- Function classification big PK! How to use sigmoid and softmax respectively?
- Experiment 1 assignment
- .NET Core 跨平台资源监控库及 dotnet tool 小工具
- Using annotation + interceptor to implement asynchronous execution
- Deep copy
- 深拷贝
- I used Python to find out all the people who deleted my wechat and deleted them automatically
猜你喜欢
如果把编程语言当武功绝学!C++是九阴真经,那程序员呢?
Newbe.ObjectVisitor Example 1
An online accident caused by improper use of thread pool
Iptables from introduction to mastery
JVM Zhenxiang series: easy understanding of class files to virtual machines (Part 2)
精通高并发与多线程,却不会用ThreadLocal?
采用注解+拦截器的方式进行异步执行的实现方式
Tasks of the first week of information security curriculum design (analysis of 7 instructions)
第一部分——第2章指针操作
[elastic search technology sharing] - ten pictures to show you the principle of ES! Understand why to say: ES is quasi real time!
随机推荐
ITerm2 配置和美化
寻找性能更优秀的不可变小字典
C + + opencv4.3 sift matching
简明 VIM 练级攻略
Learn volatile, you change your mind, I see
如何将PyTorch Lightning模型部署到生产中
To introduce to you, this is my flow chart software—— draw.io
latex入门
进程 线程 协程
使用Fastai开发和部署图像分类器应用
给大家介绍下,这是我的流程图软件 —— draw.io
Looking for a small immutable dictionary with better performance
后缀表达式转中缀表达式
Solve the failure of go get download package
git操作与分支管理规范
Countdownlatch explodes instantly! Based on AQS, why can cyclicbarrier be so popular?
. net core cross platform resource monitoring library and dotnet tool
Part 1 - Chapter 2 pointer operation
Array acquaintance
【杂谈】JS相关的线程模型整理