结构数组维度

Structure array dimensions

1x3结构数组和3x1结构数组有区别吗?据我所知,似乎没有,但我不完全确定。

是的,有区别,但只在某些时候有影响。这也适用于数字数组,因此为了简洁起见,我将在下面的示例中使用它们。

对于linear indexing,无论是行向量还是列向量都无关紧要。

a = [4, 5, 6];
b = a.';

a(1) == b(1)
a(2) == b(2)
a(3) == b(3)

不过,如果您使用二维对其进行索引,那将很重要。

% Will work
a(1, 3)

% Won't work
a(3, 1)

% Will Work
b(3, 1)

% Won't work
b(1, 3)

最重要的时间是你将它与另一个struct结合起来的时候。维度必须允许串联。

a = [1 2 3];
b = a.';

% Cannot horizontally concatenate something with 1 row with something with 3 rows
[a, b]

% You need to make sure they both have the same # of rows
[a, a]   % or [a, b.']