Last active
August 29, 2015 13:56
-
-
Save euyuil/9065428 to your computer and use it in GitHub Desktop.
Octave: matrix notes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 定义一个行向量: | |
x = [1 2 3] | |
x = | |
1 2 3 | |
% 定义一个列向量: | |
x = [1; 2; 3;] | |
x = | |
1 | |
2 | |
3 | |
% 定义一个矩阵: | |
x = [1 2 3; 4 5 6; 7 8 9] | |
x = | |
1 2 3 | |
4 5 6 | |
7 8 9 | |
% 取矩阵的第 1 行、第 2 列的值(以上面的最后赋值的矩阵 x 为例): | |
x(1, 2) | |
ans = 2 | |
% 如果你直接写 x(2),语法上也是可以的,取到的值是第 2 **行**的第一个数字: | |
x(1) | |
ans = 4 | |
% 如果你写 x(4),则取到的是第 1 行、第 2 列的数字: | |
x(4) | |
ans = 2 | |
% 冒号 : 表示整行或整列,比如 x(:, 1) 表示选取了所有的行,但是只要第 1 列: | |
x(:, 1) | |
ans = | |
1 | |
4 | |
7 | |
% 当然如果只要第一行,那么就: | |
x(1, :) | |
ans = | |
1 2 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment