【问题标题】:Multidimensional array : Split and put back together多维数组:拆分并重新组合
【发布时间】:2019-09-19 11:19:51
【问题描述】:

我正在尝试将 3 维数组“颠倒”为:

我已经尝试过inverse 函数,但是如果我们用数学术语来看待逆运算,它会给我们另一个结果。我需要在不改变数组中的数据的情况下转动。该怎么做?

为了将 3 维数组 (A x B x C) 拆分为 A 子数组 (2d, B x C),我使用了 squeeze: k=squeeze(array(n,:,:))。现在我有一个大小为B x C 的二维数组。如何将其重新组合在一起(在 3 维数组中)?

【问题讨论】:

    标签: arrays matlab matrix split reshape


    【解决方案1】:

    可以使用permute()改变维度的顺序,可以作为多维转置使用。

    然后将 2D 矩阵放入 3D 矩阵是一个简单的索引操作。阅读更多索引here

    A = rand(10,10,10);
    B = permute(A, [ 3 2 1 ]);  % Permute he order of dimensions
    
    mat1 = rand(10,10);
    mat2 = rand(10,10);
    mat_both(:,:,2) = mat2; % Stack 2D matrices along the third dimension
    mat_both(:,:,1) = mat1;
    
    mat_both = cat(3,mat1, mat2);  % Stacks along the third dimension in a faster way
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-23
      • 1970-01-01
      • 1970-01-01
      • 2017-09-02
      • 1970-01-01
      • 2015-11-18
      • 1970-01-01
      相关资源
      最近更新 更多