Octave 常用命令
GNU Octave 官方文档
GNU Octave Documentation(Online)
GNU Octave Documentation(PDF)
安装额外的包
Installing and Removing Packages
Octave Forge
% 卸载包
pkg uninstall io statistics
% 从 Octave Forge 仓库直接安装包
pkg install -forge io statistics
% 从本地文件安装包
pkg install io.2.4.12.tar.gz statistics.1.4.1.tar.gz
% 从url安装包
pkg install 'http://somewebsite.org/statistics-1.4.1.tar.gz'
% 检查 Octave Forge 仓库更新所有过期的包,更新单个包使用 install 命令
pkg update
% 加载包
pkg load statistics
% 列出当前安装的包
pkg list
% 给出包的简短描述
pkg describe -verbose statistics
Package Name | Version | Installation directory
--------------+---------+-----------------------
io *| 2.4.12 | /Users/guoli/octave/io-2.4.12
statistics *| 1.4.1 | /Users/guoli/octave/statistics-1.4.2
命令行常用设置
% 设置命令行提示符,可以将该命令添加到~/.octaverc文件中
PS('>> ')
% 显示当前环境所有变量
whos
三元操作 (ternary operation)
如果 n > 1 则返回 1,如果 n <= 1 则返回 0。此方法可用于绘制分段函数。
(n > 1) * 1
因为逻辑比较会被转换为 1 或 0,可以将逻辑比较乘以希望的输出,结果就是 0 或期望输出。
范围表达式
% 范围表达式生成一个行向量(row vector)
1 : 2 : 5 % 1 3 5
1 : -.3 : 0 % 1 0.7 0.4 0.1
1 : 5 % 1 2 3 4 5
索引表达式
a = 1 : 5;
a(1) % 1
a(end) % 5
a(2:end) % 2 3 4 5
a([2, end]) % 2 5
a(:) % change to the column-vector
% append new element to vector
a[end+1] = 6; % works for both row- and column-vectors
a = [a 6]; % works for row-vectors
a = [a; 6]; % works for column-vectors
% delete a element
a(end) = [];
# append new element to matrix
A = eye(2); % 2x2 identity matrix
A[end+1, :] = 3; % get 3x2 matrix
A[end+1, :] = [4 5]; % get 4x2 matrix
A = [A; [6 7]]; % get 5x2 matrix
A = eye(2); % 2x2 identity matrix
A[:, end+1] = 3; % get 2x3 matrix
A[:, end+1] = [4; 5]; % get 2x4 matrix
A = [A [6; 7]]; % get 2x5 matrix
交换矩阵中的两行或两列
E = eye(5);
E([3 5], :) = E([5 3], :) % 交换第3行和第5行
E(:, [4 5]) = E(:, [5 4]) % 交换第4列和第5列
生成随机数
% 生成一个随机数在1-10之间的2x3x4矩阵
randi(10, 2, 3, 4);
% 生成一个随机数在3-9之间的3x3方阵
randi([3,9], 3);
将向量 v 中的任意整数值转换成 one-hot 向量
v = 1:10;
E = eye(10);
E(:, v(3));
函数句柄和匿名函数
Function Handles
Anonymous Functions
命令与函数语法(MATLAB)
大专栏 Octave 常用命令x.html">Command vs. Function Syntax
绘图
Plot Annotations
Printing and Saving Plots
Axis Configuration
demo plot;
demo ('subplot', 1);
demo surf;
数据准备
x = linspace(-3,3,10);
y = linspace(-3,3,10);
% the rows of metrices X are copies of vector x,
% and the columns of metrices Y are copies of vector y.
[X Y] = meshgrid(x, y);
% below will always assert true
y' * x == X .* Y;
% function of sombrero
f = @(X,Y) sin(sqrt(X.^2+Y.^2))./(sqrt(X.^2+Y.^2))
Z = f(X, Y);
2D绘图
% produce 2-D plot
plot(x, y, 'k+', 'LineWidth', 2, 'MarkerSize', 7);
散点图
% draw a 3-D scatter plot
scatter3(X, Y, Z, 'filled');
等高线图
% create 2-D contour plot
contour(Z, 'ShowText', 'on');
colorbar;
% create 3-D contour plot
contour3(Z, 'ShowText', 'on');
3D网格图
% plot a 3-D wireframe mesh.
figure 1;
clf;
mesh(Z);
3D surface 图
% plot a 3-D surface mesh.
figure 1;
clf;
surf(Z);
shading interp;
colorbar;
% plot a function with lots of local maxima and minima.
surf(peaks);
peaks; % same as above
数轴设置
% axis configuration
axis;
axis([-3 3 -1 1], "square"); % "square", "equal", "normal"
axis("auto"); % "auto", "manual", "tight", "image", "vis3d"
xlim;
xlim([-3 3]);
xlim("auto");
% set axis location
set(gca, 'xaxislocation', 'origin'); % {'bottom'}, 'origin', 'top'
set(gca, 'yaxislocation', 'origin'); % {'left'}, 'origin', 'right'
set(gca, 'box', 'off');
% plot annotations
title('surface of peaks');
xlabel('x axis');
ylabel('y axis');
zlabel('z axis');
legend('peaks');
保存图形
% save picture to the file
print peaks.png
3D正态分布函数
x = y = linspace (-5, 5);
[X Y] = meshgrid(x, y);
f = @(X, Y, mu, sigma) exp (-((X - mu(1)).^2 + (Y - mu(2)).^2) ./ (2 * sigma^2));
Z = f(X, Y, [0 0], 1);
surf(X, Y, Z);
分段函数
x = linspace (-3, 3);
f1 = @(x) (-x + 1).*(x < 1) + (x - 1).*(x >= 1);
f2 = @(x) (x - 1).*(x > -1);
subplot(121);
axis square;
plot(x, f1(x), 'LineWidth', 2);
subplot(122);
axis square;
plot(x, f2(x), 'LineWidth', 2);
矩阵运算
3维矩阵转置
Z = reshape(1:24, 2, 3, 4);
permute(Z, [1,3,2]) % 将第2维与第3维进行转置
permute(Z, [3,2,1]) % 将第1维与第3维进行转置
线性代数
简化(行)阶梯形矩阵 (Reduced Row Echelon Form)
A = magic(3);
rref(A)
Octave 常用命令的更多相关文章
- MATLAB/OCTAVE常用命令 cheat sheet
MATLAB cheatsheet http://web.mit.edu/18.06/www/Spring09/matlab-cheatsheet.pdf 清除变量 clear 清屏 clc //cl ...
- Linux 常用命令(持续补充)
常用命令: command &:将进程放在后台执行 ctrl + z:暂停当前进程 并放入后台 jobs:查看当前后台任务 bg( %id):将任务转为后台执行 fg( %id):将任务调回前 ...
- LVM基本介绍与常用命令
一.LVM介绍LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制LVM - 优点:LVM通常用于装备大量磁盘的系统,但它同样适 ...
- Linux学习笔记(一):常用命令
经过统计Linux中能够识别的命令超过3000种,当然常用的命令就远远没有这么多了,按照我的习惯,我把已经学过的Linux常用命令做了以下几个方面的分割: 1.文件处理命令 2.文件搜索命令 3.帮助 ...
- git常用命令(持续更新中)
git常用命令(持续更新中) 本地仓库操作git int 初始化本地仓库git add . ...
- 【原】npm 常用命令详解
今年上半年在学习gulp的使用,对npm的掌握是必不可少的,经常到npm官网查询文档让我感到不爽,还不如整理了一些常用的命令到自己博客上,于是根据自己的理解简单翻译过来,终于有点输出,想学习npm这块 ...
- npm常用命令
npm常用命令 环境:win7 npm 是什么 NPM(node package manager),通常称为node包管理器.顾名思义,它的主要功能就是管理node包,包括:安装.卸载.更新.查看.搜 ...
- Git 常用命令
一.初始環境配置 git config --global user.name "John Doe"git config --global user.email johndoe@ex ...
- linux iptables常用命令之配置生产环境iptables及优化
在了解iptables的详细原理之前,我们先来看下如何使用iptables,以终为始,有可能会让你对iptables了解更深 所以接下来我们以配置一个生产环境下的iptables为例来讲讲它的常用命令 ...
随机推荐
- CTF -攻防世界-crypto新手区(5~11)
easy_RSA 首先如果你没有密码学基础是得去恶补一下的 然后步骤是先算出欧拉函数 之后提交注意是cyberpeace{********}这样的 ,博主以为是flag{}耽误了很长时间 明明没算错 ...
- WOJ 1543 Array
还是聪哥给我讲的思路才知道的,起初我利用两两互质去求发现有问题,互质只是必要条件而非充分条件,后来还是用的标准思路 即其实最终只要保留最大的素数的幂即可,其他包含该素数幂但指数低的都不用了,这样就能保 ...
- ZOJ 2301/HDU 1199 线段树+离散化
给这个题目跪了两天了,想吐简直 发现自己离散化没学好 包括前一个离散化的题目,实际上是错了,我看了sha崽的博客后才知道,POJ那题简直数据弱爆了,本来随便一组就能让我WA掉的,原因在于离散化的时候, ...
- JOIN US | 京东云诚聘技术精英
清新的办公区域感受自然的气息,温馨的团队为你我放飞青春的理想 上有天文下有地理的阅读区域 各类图书提供借阅 绿植环绕生机勃勃的会客区域洋溢青春 [高级Java工程师] 职位描述: 参与云计算相关平台/ ...
- cpu压测测试--------自己设定cpu需要跑到的压力
下载压力测试包 https://pan.baidu.com/s/1DJYAzBHHDxMViy5dMel2Lw 提取码:a5j3 使用方法: 方法一:前端启动,按Ctrl+c结束 java -Dbus ...
- pywin32获得tkinter窗口句柄,并在上面绘图
想实现用win32 API在tkinter窗口上画图,那么应该先获得tkinter窗口的句柄hwnd,然后再获得tkinter的设备hdc.尝试了FindWindow(),GetActiveWindo ...
- python编程:从入门到实践----第六章>字典
一.一个简单的字典:alien_0存储外星人的颜色和点数,使用print打印出来 alien_0 = {'color': 'green','points': 5} print(alien_0['col ...
- HCTF2018-admin
记录一道比较有意思的题目,对于萌新来说能学到很多东西orz.. 三种解法: 1: flask session 伪造 2: unicode欺骗 3: 条件竞争 注册账户查看源码: 发现提示,根据提示和题 ...
- Springmvc接收数组参数
Springmvc接收数组参数,必须添加@RequestParam注解 注解格式@RequestParam(value="前端参数名[]") 示例: controller端的代码 ...
- 合并两个django的queryset
有queryset:A和B 要合并它们,根据网上的答案,貌似是用itertools库的chain对象比较好,地址 c=chain(x,y) 但是当c用于分页的时候,就有问题,会报chain没有le ...