【问题标题】:MATLAB: Transform 3D into 2D (concatenation)MATLAB:将 3D 转换为 2D(连接)
【发布时间】:2017-10-07 14:37:57
【问题描述】:

我需要将 3D 数组 s 转换为 2D 数组 sReshape,其中第三维的每个切片都将简单地放在第一个切片的 2D 数组的行下方。

这是示例以及预期的解决方案:

s = reshape((1:30),[5,3,2]);
sReshape = ???

resultExpected = [(1:5),(16:20) ; (6:10),(21:25) ; (11:15),(26:30)]';
isequal(sReshape, resultExpected)

【问题讨论】:

    标签: arrays matlab multidimensional-array reshape


    【解决方案1】:

    你可以在重塑之前使用permute在第二和第三维度之间切换:

    s = reshape((1:30),[5,3,2]);
    % switch between the 2nd and third dimensions
    y = permute(s,[1 3 2]);
    % reshape into 3 columns matrix
    sReshape = reshape(y,[],3);
    
    resultExpected = [(1:5),(16:20) ; (6:10),(21:25) ; (11:15),(26:30)]';
    isequal(sReshape, resultExpected)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-11
      • 2013-03-28
      • 2017-09-04
      • 1970-01-01
      相关资源
      最近更新 更多