标签:ack nta 准备 end src matrix 一个 desc sam
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
如果 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 = 1:10;
E = eye(10);
E(:, v(3));
Function Handles
Anonymous Functions
大专栏 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);
% 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');
% plot a 3-D wireframe mesh.
figure 1;
clf;
mesh(Z);
% 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
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);
Z = reshape(1:24, 2, 3, 4);
permute(Z, [1,3,2]) % 将第2维与第3维进行转置
permute(Z, [3,2,1]) % 将第1维与第3维进行转置
A = magic(3);
rref(A)
标签:ack nta 准备 end src matrix 一个 desc sam
原文地址:https://www.cnblogs.com/lijianming180/p/12375990.html