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:
constructing a 3D array (using permute?)

Subject: constructing a 3D array (using permute?)

From: Dave Brackett

Date: 22 Jul, 2008 17:45:06

Message: 1 of 2

I have some code as follows:

 a=rand(50,16)
 b=pi*a.^2

 f=1:100
 w=2*pi*f

 c=sqrt((w'.*b)/(pi))


This returns an error stating that the matrix dimensions
must agree as would be expected because w' is [100 1] and b
is [50 16].

My question is, how can I assemble a 3D array of size [100
16 50] to be stored as c, from w' and b?

I think permute is needed but can't get it to do what I want.
Hopefully you can help. Thanks.

Subject: constructing a 3D array (using permute?)

From: Roger Stafford

Date: 22 Jul, 2008 19:04:03

Message: 2 of 2

"Dave Brackett" <davebrackett@hotmail.com> wrote in message <g656b2
$4o1$1@fred.mathworks.com>...
> I have some code as follows:
>
> a=rand(50,16)
> b=pi*a.^2
>
> f=1:100
> w=2*pi*f
>
> c=sqrt((w'.*b)/(pi))
>
>
> This returns an error stating that the matrix dimensions
> must agree as would be expected because w' is [100 1] and b
> is [50 16].
>
> My question is, how can I assemble a 3D array of size [100
> 16 50] to be stored as c, from w' and b?
>
> I think permute is needed but can't get it to do what I want.
> Hopefully you can help. Thanks.

  I believe you need to first use 'shiftdim' by -1 with b, producing a three-
dimensional array with a first dimension singleton. Then apply 'bsxfun' with
"@times" using this and w/pi.

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