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 a matrix (can I use reshape or reshapec?)

Subject: reshape a matrix (can I use reshape or reshapec?)

From: mobileT83 T

Date: 20 May, 2010 16:06:06

Message: 1 of 5

I would like to take a MxNxL matrix and get a M*NxL matrix. I know I can do this with two for loops

A = MxNxL
for ii = 1:N
for jj = 1:M

a = A(jj,ii,:);

end
end

but I was hoping to you a reshape tool. And I want to keep the order given in this for loop.

I found this but I don't know if it will help me... maybe I don't get it.
http://www.mathworks.com/matlabcentral/fileexchange/20255

Thanks

mobile

Subject: reshape a matrix (can I use reshape or reshapec?)

From: Roger Stafford

Date: 20 May, 2010 18:02:19

Message: 2 of 5

"mobileT83 T" <mobileT83@gmail.com> wrote in message <ht3mle$9re$1@fred.mathworks.com>...
> I would like to take a MxNxL matrix and get a M*NxL matrix. I know I can do this with two for loops
>
> A = MxNxL
> for ii = 1:N
> for jj = 1:M
>
> a = A(jj,ii,:);
>
> end
> end
>
> but I was hoping to you a reshape tool. And I want to keep the order given in this for loop.
>
> I found this but I don't know if it will help me... maybe I don't get it.
> http://www.mathworks.com/matlabcentral/fileexchange/20255
>
> Thanks
>
> mobile

  Do:

 a = reshape(A,[],L);

  It is incompatible with the very notion of an M*N by L matrix to have the ordering you give from your for-loops. If I interpret your for-loop correctly, each set of L entries occurs in the most rapid ordering sequence, followed by the M and then the N entries. An M*N by L array doesn't work this way.

Roger Stafford

Subject: reshape a matrix (can I use reshape or reshapec?)

From: Matt Fig

Date: 20 May, 2010 18:15:26

Message: 3 of 5

Perhaps

permute(A,[2 1 3])

will do what you need.

Subject: reshape a matrix (can I use reshape or reshapec?)

From: mobileT83 T

Date: 21 May, 2010 01:28:03

Message: 4 of 5

Thank you for the advice, I understand what you are saying, I really need a table... and they would have values corresponding to the values in each M, N, and L dimensions.

Basically I need to take all of M and lay them out like below... in this case they go 1 through 4 and repeat, N on the other hand only changes when a new set of M starts and finally L is a 2d matrix M*NxL.

this is the new set of matrices I want to make from the 3d matrix... M and N are indexing L.
M N L
1 1 [random values]
2 1 [random values]
3 1 [random values]
4 1 [random values]
1 2 [random values]
2 2 [random values]
3 2 [random values]
4 2 [random values]

"Matt Fig" <spamanon@yahoo.com> wrote in message <ht3u7u$2u2$1@fred.mathworks.com>...
> Perhaps
>
> permute(A,[2 1 3])
>
> will do what you need.

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ht3tfb$aqm$1@fred.mathworks.com>...
> "mobileT83 T" <mobileT83@gmail.com> wrote in message <ht3mle$9re$1@fred.mathworks.com>...
> > I would like to take a MxNxL matrix and get a M*NxL matrix. I know I can do this with two for loops
> >
> > A = MxNxL
> > for ii = 1:N
> > for jj = 1:M
> >
> > a = A(jj,ii,:);
> >
> > end
> > end
> >
> > but I was hoping to you a reshape tool. And I want to keep the order given in this for loop.
> >
> > I found this but I don't know if it will help me... maybe I don't get it.
> > http://www.mathworks.com/matlabcentral/fileexchange/20255
> >
> > Thanks
> >
> > mobile
>
> Do:
>
> a = reshape(A,[],L);
>
> It is incompatible with the very notion of an M*N by L matrix to have the ordering you give from your for-loops. If I interpret your for-loop correctly, each set of L entries occurs in the most rapid ordering sequence, followed by the M and then the N entries. An M*N by L array doesn't work this way.
>
> Roger Stafford

Subject: reshape a matrix (can I use reshape or reshapec?)

From: mobileT83 T

Date: 21 May, 2010 10:38:04

Message: 5 of 5

This worked perfectlly!!! I just had trouble testing it. Is there any way I could get vectors M and N returned in the correct order corresponding to
M N L
1 1 [random values]
2 1 [random values]
3 1 [random values]
4 1 [random values]
1 2 [random values]
2 2 [random values]
3 2 [random values]
4 2 [random values]

L is what was returned by a = reshape(A,[],L);

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ht3tfb$aqm$1@fred.mathworks.com>...
> "mobileT83 T" <mobileT83@gmail.com> wrote in message <ht3mle$9re$1@fred.mathworks.com>...
> > I would like to take a MxNxL matrix and get a M*NxL matrix. I know I can do this with two for loops
> >
> > A = MxNxL
> > for ii = 1:N
> > for jj = 1:M
> >
> > a = A(jj,ii,:);
> >
> > end
> > end
> >
> > but I was hoping to you a reshape tool. And I want to keep the order given in this for loop.
> >
> > I found this but I don't know if it will help me... maybe I don't get it.
> > http://www.mathworks.com/matlabcentral/fileexchange/20255
> >
> > Thanks
> >
> > mobile
>
> Do:
>
> a = reshape(A,[],L);
>
> It is incompatible with the very notion of an M*N by L matrix to have the ordering you give from your for-loops. If I interpret your for-loop correctly, each set of L entries occurs in the most rapid ordering sequence, followed by the M and then the N entries. An M*N by L array doesn't work this way.
>
> 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