From: Jan Simon on
Dear Brian,

x = reshape(1:256*256, 256, 256);
y = permute(reshape(x, 8, 32, 8, 32), [1, 3, 2, 4]);
y = reshape(y, 8, 8, 1024);
Now y has leading blocks of the wanted size. For the backward transformation use IPERMUTE.

Good luck, Jan
From: Matt J on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i3s84g$4vp$1(a)fred.mathworks.com>...
> > 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] ) );
===================

Although, truthfully, BLOCKPROC is probably still the most direct approach


%forward reshape
tmp=blockproc(A,[8,8],@(s) s.data(:) );
B=reshape(tmp,64,[]);

%reverse reshape
tmp=reshape(B,64*32,[]);
AA=blockproc(tmp,[64,1],@(s) reshape(s.data,[8,8]) );
From: Matt J on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i3sds9$emg$1(a)fred.mathworks.com>...

>
> Although, truthfully, BLOCKPROC is probably still the most direct approach
========

Hmmm. But it's also the slowest by far of those considered,


A=rand(256);

%%% Using cell2mat
tic;
tmp=mat2cell(A,ones(1,32)*8,ones(1,32)*8 );
ReshapedMatrix=reshape( cell2mat(tmp(:).'), 64,[]);
toc;
%Elapsed time is 0.016849 seconds.


%%%% Using permute
tic;
y = permute(reshape(A, 8, 32, 8, 32), [1, 3, 2, 4]);
y = reshape(y, 8, 8, 1024);
toc;
%Elapsed time is 0.001925 seconds.


%%%% Using blockprock
tic;

tmp=blockproc(A,[8,8],@(s) s.data(:) );
B=reshape(tmp,64,[]);

toc;
%Elapsed time is 0.416035 seconds.
From: us 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.

a hint:
- see peter acklam's seminal paper
MATLAB array manipulation tips and tricks
for a wealth of ideas...
- for your particular problem, peruse page 9

home.online.no/~pjacklam/matlab/doc/mtt/doc/mtt.pdf

for further ref re pa, see

http://matlabwiki.mathworks.com/MATLAB_FAQ#What_is_Acklamization.3F

us
First  |  Prev  | 
Pages: 1 2
Prev: Chemical Markup Language
Next: an easy question