Skip to content

Instantly share code, notes, and snippets.

@euyuil
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save euyuil/9065428 to your computer and use it in GitHub Desktop.
Save euyuil/9065428 to your computer and use it in GitHub Desktop.
Octave: matrix notes.
% 定义一个行向量:
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