2

I have a 3-dimensional matrix of dimensions: 427x470x48

I want to reshape this into a 2-dimensional matrix of dimensions: 48x200690

This would mean that old(1, 1, :) would correspond to new(:, 1)

Additionally, old(1,2,:) would correspond to new(:,2) and so on and so forth.

Thank You

Shaayaan Sayed
  • 231
  • 2
  • 5
  • 13

1 Answers1

3

Do:

new = reshape(permute(old, [3 2 1]), 48, []);

Also you can roughly check that they are equal by:

numel(intersect(old(1,1,:),new(:,1))) == 48;
voxeloctree
  • 839
  • 6
  • 13
  • 1
    This will not put the third dimension first as was requested. – erikced Aug 01 '13 at 21:45
  • Suggestions: a slight improvement would be `new = reshape(permute(old, [3 2 1]), 48, []);` . This `[]` computes the product of the other dimensions and assigns it to the last dimension of the `reshape`. Thus, as long as you want a `48xn` output, `n` will always be right. – Floris Aug 01 '13 at 23:08