【问题标题】:Structure array dimensions结构数组维度
【发布时间】:2016-08-13 14:32:43
【问题描述】:

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

【问题讨论】:

    标签: arrays matlab structure matlab-struct


    【解决方案1】:

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

    对于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.']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多