From: Brian on
Say I have a 256x256 matrix. We can look at this as 1024, 8x8 blocks
of data. Now, I want to reshape the original 256x256 matrix into
another matrix so that each column is one of those blocks. So the
reshaped matrix will have 64 rows and 1024 columns and then reshape it
back to its original square matrix after some operations. I suspect
some form of BLKPROC can do this but nevertheless I am interested in a
more direct approach.
From: Andy on
Brian <bijan.mobasseri(a)gmail.com> wrote in message <a1723d76-3bec-4e96-8e48-2a1a7ad80931(a)5g2000yqz.googlegroups.com>...
> Say I have a 256x256 matrix. We can look at this as 1024, 8x8 blocks
> of data. Now, I want to reshape the original 256x256 matrix into
> another matrix so that each column is one of those blocks. So the
> reshaped matrix will have 64 rows and 1024 columns and then reshape it
> back to its original square matrix after some operations. I suspect
> some form of BLKPROC can do this but nevertheless I am interested in a
> more direct approach.

Each block becomes one column, but it's unclear in which order the blocks should become columns. Could you post a small sample (say, 16x16, with four blocks) array and your desired output?
From: Matt J on


tmp=mat2cell(YourMatrix,ones(1,32)*8,ones(1,32)*8 );
ReshapedMatrix=reshape( cell2mat(tmp(:).'), 64,[]);
From: Brian on
On Aug 10, 11:41 am, "Matt J " <mattjacREM...(a)THISieee.spam> wrote:
>  tmp=mat2cell(YourMatrix,ones(1,32)*8,ones(1,32)*8 );
>  ReshapedMatrix=reshape(  cell2mat(tmp(:).'), 64,[]);

Matt-- It works. I would have never thought of this because I almost
never use cell arrays, nor do I fully appreciate them. How would
reshaping back to the original dimensions work?
Andy- The order can be raster scan from top-left to bottom-right. As
long as they can go back to their original locations it is fine.
From: Matt J on
Brian <bijan.mobasseri(a)gmail.com> wrote in message <bb19b632-c60c-427c-8780-6ba7dd96fd68(a)x25g2000yqj.googlegroups.com>...
> On Aug 10, 11:41 am, "Matt J " <mattjacREM...(a)THISieee.spam> wrote:
> >  tmp=mat2cell(YourMatrix,ones(1,32)*8,ones(1,32)*8 );
> >  ReshapedMatrix=reshape(  cell2mat(tmp(:).'), 64,[]);
>
> Matt-- It works. I would have never thought of this because I almost
> never use cell arrays, nor do I fully appreciate them. How would
> reshaping back to the original dimensions work?
==================

Same kind of thing in reverse....

tmp= reshape(ReshapedMatrix,8,[]);
tmp=mat2cell(tmp, 8,ones(1,1024)*8);
YourMatrix=cell2mat(reshape(tmp, [32,32] ) );
 |  Next  |  Last
Pages: 1 2
Prev: Chemical Markup Language
Next: an easy question