如何在Matlab/Octave中访问单个矩阵元素?

3 matlab matrix octave

假设我有:

>> X = magic(5)
X =

   17   24    1    8   15
   23    5    7   14   16
    4    6   13   20   22
   10   12   19   21    3
   11   18   25    2    9
Run Code Online (Sandbox Code Playgroud)

我如何从第二列获得元素?

我已经知道Octave中的(某些?)集合中的索引是基于一个的,但我不确定它是否也适用于矩阵.

car*_*aug 12

请参阅手册的索引表达式部分.要从第二列获取第i个元素:

X(i,2)      # element 'i' from column 2
X(1:end,2)  # the whole 2nd column
X(:,2)      # same thing but shorter
x(:, [2 3]) # whole 2nd and 3rd column
Run Code Online (Sandbox Code Playgroud)

请注意,Octave是一种语言,其中数组元素按列主要顺序排列.