一个Matlab矩阵允许有多少个索引?
我正在学习Matlab(实际上是八度音阶),有些东西让我很困惑:一个Matlab矩阵允许有多少个索引?,matlab,matrix,octave,Matlab,Matrix,Octave,我正在学习Matlab(实际上是八度音阶),有些东西让我很困惑: octave:14> a = [2 3 4] a = 2 3 4 octave:15> a(1) ans = 2 octave:16> a(1,1) ans = 2 octave:17&
octave:14> a = [2 3 4]
a =
2 3 4
octave:15> a(1)
ans = 2
octave:16> a(1,1)
ans = 2
octave:17> a(1,1,1)
ans = 2
octave:18> a(1,1,2)
error: A(I,J,...): index to dimension 3 out of bounds; value 2 out of bound 1
octave:18> a(2,1,1)
error: A(I,J,...): index to dimension 1 out of bounds; value 2 out of bound 1
我以为a(1,1,1)
是非法的,但这让我很困惑。。。一个矩阵允许有多少个索引
当我说
a(1,1,1)
是什么意思?在数组中,只要数组不是空的,第一行、第一列、第一页等都是定义的
所以如果
a = 3;
a(1) %# works
a(1,1) %# works
a(1,1,1) %# works
a(1,1,1,1) %# works
因为a
的大小理论上是[1,1,1,1,1,…]
为方便起见,标量的大小表示为[1,1]
,即不提及长度1的其他维度