Stuart’s MATLAB VideosWatch and Learn

This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

How to do a matrix reshape by ‘blocks’6

Posted by Doug Hull,

This week’s video covers a non-standard way of reshaping a matrix. Instead of using the reshape function, this kind of matrix manipulation must be done with for loops. This matrix reshape operation treats submatrices within the original matrix as a unit. I suspect there are many other ways of doing this, and would love to hear about them in the comments.

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!