Comments on: How to do a matrix reshape by ‘blocks’ https://blogs.mathworks.com/videos/2012/01/10/how-to-do-a-matrix-reshape-by-blocks/?s_tid=feedtopost Stuart uses video to share his experiences solving problems with MATLAB day-to-day, interesting new features, plus tips and tricks he has picked up along the way. Wed, 23 Jan 2019 19:52:53 +0000 hourly 1 https://wordpress.org/?v=6.2.2 By: Sulaymon Eshkabilov https://blogs.mathworks.com/videos/2012/01/10/how-to-do-a-matrix-reshape-by-blocks/#comment-89076 Wed, 23 Jan 2019 19:52:53 +0000 https://blogs.mathworks.com/videos/?p=570#comment-89076 Make it simple but not simpler … :). This is all what is needed to avoid any loops from the given task on step 1 and 2.
imagesc(repmat(((reshape((1:9),3,3))+750), 4,5))

]]>
By: Sulaymon Eshkabilov https://blogs.mathworks.com/videos/2012/01/10/how-to-do-a-matrix-reshape-by-blocks/#comment-89072 Wed, 23 Jan 2019 19:20:13 +0000 https://blogs.mathworks.com/videos/?p=570#comment-89072 Here is a simpler one-liner code without any loop iteration:
NEWmat = repmat(longMAT(1:3,:), 4, 5);

]]>
By: doug https://blogs.mathworks.com/videos/2012/01/10/how-to-do-a-matrix-reshape-by-blocks/#comment-24440 Mon, 10 Jun 2013 17:29:28 +0000 https://blogs.mathworks.com/videos/?p=570#comment-24440 @Yesid,

Am I missing something? Aren’t they already concatenated? How is xyz different than what you are trying to get for cc?

]]>
By: Yesid https://blogs.mathworks.com/videos/2012/01/10/how-to-do-a-matrix-reshape-by-blocks/#comment-24436 Mon, 10 Jun 2013 10:04:56 +0000 https://blogs.mathworks.com/videos/?p=570#comment-24436 hello..

How do I automatically concatenate several pages of the same multidimensional array.?

cc=cat(1,xyz(:,:,1),xyz(:,:,2),xyz(:,:,3),…,xyz(:,:,n));

]]>
By: Sean de Wolski https://blogs.mathworks.com/videos/2012/01/10/how-to-do-a-matrix-reshape-by-blocks/#comment-2969 Tue, 17 Jan 2012 16:31:04 +0000 https://blogs.mathworks.com/videos/?p=570#comment-2969 And the obligatory one-liner without cells:

%Some parameters
blksz = 3; %block size in row/col
nrep = 20; %block repetitions
nr = 4; %number of rows of blocks
nc = 5; %number of columns of blocks

%Determinant sample data
A = reshape(1:(blksz*blksz*nrep),blksz,[])’;

%Engine one line version:
NewA = reshape(permute(reshape(permute(reshape(A.’,blksz,blksz,[]),[2 1 3]),blksz,blksz*nc,[]),[2 1 3]),blksz*nc,blksz*nr)’;

%Engine in pieces:
B = reshape(A.’,blksz,blksz,[]); %reshape the transpose to 3d with each block a 3×3
C = permute(B,[2 1 3]); %transpose each block
D = reshape(C,blksz,blksz*nc,[]); %reshape to nr planes that need to be stacked vertically
E = permute(D,[2 1 3]); %transpose each plane
F = reshape(E,blksz*nc,blksz*nr)’; %reshape into a matrix and transpose

]]>
By: Matt Fig https://blogs.mathworks.com/videos/2012/01/10/how-to-do-a-matrix-reshape-by-blocks/#comment-2967 Fri, 13 Jan 2012 02:00:39 +0000 https://blogs.mathworks.com/videos/?p=570#comment-2967 Here is one version of the obligatory one-liner.

newMat=cell2mat(reshape(mat2cell(longMat,rSize*ones(1,n),cSize),5,4).');

However, this is only significantly faster for large systems.

I have written optimized, hard-to-read MATLAB code in the past, and in order to help those who might be reading it in the future I often put the straightforward FOR loop(s) version in the comments. This serves several purposes. Among them are that it lets any future user see more easily what is going on and quickly get to maintenance concerns.

Thanks for another great video, Doug!

]]>