Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Reshape

Subject: Reshape

From: Jerry

Date: 15 Nov, 2012 20:35:15

Message: 1 of 2

Hello,

A=rand (201,7152);

"A" is a matrix and I would like to reshape "A" to "B"

B=reshape (A,59898,24);

"B" is not going to be what I expected since it is getting mixed up. For example

C=A(:,1:24);
D=B(1:201,:);

isequal(C, D)

ans =

     0
How can I reshape "A" to get "C" equal with "D".

Thanks,
Jerry

Subject: Reshape

From: Roger Stafford

Date: 16 Nov, 2012 00:43:15

Message: 2 of 2

"Jerry " <jerrycholo@gmail.com> wrote in message <k83jm3$4o1$1@newscl01ah.mathworks.com>...
> Hello,
>
> A=rand (201,7152);
>
> "A" is a matrix and I would like to reshape "A" to "B"
>
> B=reshape (A,59898,24);
>
> "B" is not going to be what I expected since it is getting mixed up. For example
>
> C=A(:,1:24);
> D=B(1:201,:);
>
> isequal(C, D)
>
> ans =
>
> 0
> How can I reshape "A" to get "C" equal with "D".
>
> Thanks,
> Jerry
- - - - - - - - -
  To get the kind of rearrangement you have in mind takes more than a simple 'reshape'. One has to do a little permuting first. Do this:

 r = 298; % The number of your blocks
 [p,t] = size(A); % p = 201, t = 7152
 q = t/r; % t must be divisible by r, q = 24
 s = 0:p*q*r-1;
 B = reshape(A(1+s+p*((q-1)*floor(s/p)-(q*r-1)*floor(s/(p*r)))),p*r,q);

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us