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:
reshaping matrix

Subject: reshaping matrix

From: Snow White

Date: 18 May, 2010 10:23:04

Message: 1 of 11

hello,

i have a row vector of length p. i want to transform it to a 3d matrix where the there r 3 row each row should be similar to the previous row (they are just copies). number of columns is pmn where mn is the size of another matrix and the depth of the resultant matrix is p.

how can i do this?

bye

Subject: reshaping matrix

From: TideMan

Date: 18 May, 2010 10:43:30

Message: 2 of 11

On May 18, 10:23 pm, "Snow White" <gulesa...@gmail.com> wrote:
> hello,
>
> i have a row vector of length p. i want to transform it to a 3d matrix where the there r 3 row each row should be similar to the previous row (they are just copies). number of columns is pmn where mn is the size of another matrix and the depth of the resultant matrix is p.
>
> how can i do this?
>
> bye

You can't.
The row vector,say R, must be 3*pmn*p long.
Then:
M=reshape(R,3,pmn,p);

Subject: reshaping matrix

From: Snow White

Date: 18 May, 2010 10:59:06

Message: 3 of 11

i tried it as follows

a=[1 0]

a = 1 0

 M=reshape(a,3,2*2*10,2);
??? Error using ==> reshape
To RESHAPE the number of elements must not change.
and the above error


TideMan <mulgor@gmail.com> wrote in message <1da1eddd-078d-4a52-88d9-bb02624f1e48@g5g2000pre.googlegroups.com>...
> On May 18, 10:23 pm, "Snow White" <gulesa...@gmail.com> wrote:
> > hello,
> >
> > i have a row vector of length p. i want to transform it to a 3d matrix where the there r 3 row each row should be similar to the previous row (they are just copies). number of columns is pmn where mn is the size of another matrix and the depth of the resultant matrix is p.
> >
> > how can i do this?
> >
> > bye
>
> You can't.
> The row vector,say R, must be 3*pmn*p long.
> Then:
> M=reshape(R,3,pmn,p);

Subject: reshaping matrix

From: Steven Lord

Date: 18 May, 2010 13:30:59

Message: 4 of 11


"Snow White" <gulesaman@gmail.com> wrote in message
news:hstrtq$rkp$1@fred.mathworks.com...
>i tried it as follows
>
> a=[1 0]
>
> a = 1 0
>
> M=reshape(a,3,2*2*10,2);
> ??? Error using ==> reshape
> To RESHAPE the number of elements must not change.
> and the above error

Yes, as TideMan said that WILL NOT WORK, and the error message you received
indicated WHY it doesn't work.

What do you expect the result to be when you perform this transformation on
a = [1 0]? Perhaps seeing that will give us some insight into what you're
trying to do.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: reshaping matrix

From: Snow White

Date: 18 May, 2010 13:53:04

Message: 5 of 11

I want [a] to be arranged such that the resultant matrix has three rows and pmn columns and the depth of the matrix is p which is the length of vector a.so in the third dimension the first dimension will have all ones and then the second will have 0s and so on..

actually i have a vector p=[1,2,3,4,5...19]

i hope i cam clear enough

"Steven Lord" <slord@mathworks.com> wrote in message <hsu4qe$chs$1@fred.mathworks.com>...
>
> "Snow White" <gulesaman@gmail.com> wrote in message
> news:hstrtq$rkp$1@fred.mathworks.com...
> >i tried it as follows
> >
> > a=[1 0]
> >
> > a = 1 0
> >
> > M=reshape(a,3,2*2*10,2);
> > ??? Error using ==> reshape
> > To RESHAPE the number of elements must not change.
> > and the above error
>
> Yes, as TideMan said that WILL NOT WORK, and the error message you received
> indicated WHY it doesn't work.
>
> What do you expect the result to be when you perform this transformation on
> a = [1 0]? Perhaps seeing that will give us some insight into what you're
> trying to do.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

Subject: reshaping matrix

From: Snow White

Date: 18 May, 2010 13:54:04

Message: 6 of 11

i have tried using this...

[x y z]=size(phi);
polang=transpose(polang);
p_ang=permute(reshape(repmat(polang,1,x*y),length(polang),x,y),[2 3 1]);

"Snow White" <gulesaman@gmail.com> wrote in message <hstrtq$rkp$1@fred.mathworks.com>...
> i tried it as follows
>
> a=[1 0]
>
> a = 1 0
>
> M=reshape(a,3,2*2*10,2);
> ??? Error using ==> reshape
> To RESHAPE the number of elements must not change.
> and the above error
>
>
> TideMan <mulgor@gmail.com> wrote in message <1da1eddd-078d-4a52-88d9-bb02624f1e48@g5g2000pre.googlegroups.com>...
> > On May 18, 10:23 pm, "Snow White" <gulesa...@gmail.com> wrote:
> > > hello,
> > >
> > > i have a row vector of length p. i want to transform it to a 3d matrix where the there r 3 row each row should be similar to the previous row (they are just copies). number of columns is pmn where mn is the size of another matrix and the depth of the resultant matrix is p.
> > >
> > > how can i do this?
> > >
> > > bye
> >
> > You can't.
> > The row vector,say R, must be 3*pmn*p long.
> > Then:
> > M=reshape(R,3,pmn,p);

Subject: reshaping matrix

From: Walter Roberson

Date: 18 May, 2010 14:06:42

Message: 7 of 11

Snow White wrote:

> i have a row vector of length p. i want to transform it to a 3d matrix
> where the there r 3 row each row should be similar to the previous row
> (they are just copies).

See repmat()

Subject: reshaping matrix

From: Steven Lord

Date: 18 May, 2010 14:18:46

Message: 8 of 11


"Snow White" <gulesaman@gmail.com> wrote in message
news:hsu640$9pq$1@fred.mathworks.com...
>I want [a] to be arranged such that the resultant matrix has three rows and
>pmn columns and the depth of the matrix is p which is the length of vector
>a.so in the third dimension the first dimension will have all ones and then
>the second will have 0s and so on..
>
> actually i have a vector p=[1,2,3,4,5...19]
>
> i hope i cam clear enough

I think I understand what you're asking for, but what I asked for was the
specific result that you expected.

Okay, let's do something a little different. Let's assume that we have a
function called snowwhite that does what you want. When I call that
function:

a = [1 2 3 4];
b = snowwhite(a)

I want you to state EXPLICITLY what the contents of b are. Complete the
statement below so that it creates EXACTLY the array b that you want
snowwhite(a) to return. If you need to define other variables first so that
you can use them in the statement that defines b, that's fine but you must
include them as part of the code you write in your reply.

    b = cat(3, [

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: reshaping matrix

From: Snow White

Date: 18 May, 2010 14:58:05

Message: 9 of 11

i want b to be as follows:

b(:,:,1)=[1 1 1;1 1 1...]
b(:,:,2)=[2 2 2;2 2 2...]
b(:,:,4)=[4 4 4;4 4 4...]

"Steven Lord" <slord@mathworks.com> wrote in message <hsu7k1$m0m$1@fred.mathworks.com>...
>
> "Snow White" <gulesaman@gmail.com> wrote in message
> news:hsu640$9pq$1@fred.mathworks.com...
> >I want [a] to be arranged such that the resultant matrix has three rows and
> >pmn columns and the depth of the matrix is p which is the length of vector
> >a.so in the third dimension the first dimension will have all ones and then
> >the second will have 0s and so on..
> >
> > actually i have a vector p=[1,2,3,4,5...19]
> >
> > i hope i cam clear enough
>
> I think I understand what you're asking for, but what I asked for was the
> specific result that you expected.
>
> Okay, let's do something a little different. Let's assume that we have a
> function called snowwhite that does what you want. When I call that
> function:
>
> a = [1 2 3 4];
> b = snowwhite(a)
>
> I want you to state EXPLICITLY what the contents of b are. Complete the
> statement below so that it creates EXACTLY the array b that you want
> snowwhite(a) to return. If you need to define other variables first so that
> you can use them in the statement that defines b, that's fine but you must
> include them as part of the code you write in your reply.
>
> b = cat(3, [
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

Subject: reshaping matrix

From: Steven Lord

Date: 18 May, 2010 17:21:46

Message: 10 of 11


"Snow White" <gulesaman@gmail.com> wrote in message
news:hsu9tt$r8j$1@fred.mathworks.com...
>i want b to be as follows:
>
> b(:,:,1)=[1 1 1;1 1 1...]
> b(:,:,2)=[2 2 2;2 2 2...]
> b(:,:,4)=[4 4 4;4 4 4...]

That's getting _closer_ to what I asked for, but you're still not there.
SPECIFICALLY how many columns do you want b to have?



I believe what you want, assuming you know how many rows and columns you
want, is:

b = repmat(reshape(a, 1, 1, []), numRows, numCols, 1)

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: reshaping matrix

From: Snow White

Date: 19 May, 2010 09:34:04

Message: 11 of 11

number of columns=mxn which is the number of row multiplied by columns
"Steven Lord" <slord@mathworks.com> wrote in message <hsuib5$hu2$1@fred.mathworks.com>...
>
> "Snow White" <gulesaman@gmail.com> wrote in message
> news:hsu9tt$r8j$1@fred.mathworks.com...
> >i want b to be as follows:
> >
> > b(:,:,1)=[1 1 1;1 1 1...]
> > b(:,:,2)=[2 2 2;2 2 2...]
> > b(:,:,4)=[4 4 4;4 4 4...]
>
> That's getting _closer_ to what I asked for, but you're still not there.
> SPECIFICALLY how many columns do you want b to have?
>
>
>
> I believe what you want, assuming you know how many rows and columns you
> want, is:
>
> b = repmat(reshape(a, 1, 1, []), numRows, numCols, 1)
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

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