Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Replicating an array into a 3D layered matrix - Help please!
Replies: 0

 Jordan Posts: 4 Registered: 1/22/12
Replicating an array into a 3D layered matrix - Help please!
Posted: Jan 14, 2013 4:34 PM

Hi all. I'm struggling with some coding and can't seem to figure it out. I'd prefer to do this without for-loops.

I have a vector of length N. For now, let's say it's length 3: [A,B,C]'

I want to replicate this into a layered matrix size (2,2,N), so for this case (2,2,3).

I want the first layer (:,:,1) to look like this:
[A,A;
A,A]

The second layer (:,:,2) to look like this:
[B,B;
B,B]

The third layer (:,:,3) to look like this:
[C,C;
C,C]

And so on, through N.

So basically I want to take a vector of N ingredients and make a cake with N tiers, each tier being 2x2 and consisting of only one corresponding ingredient from (1:N). Hope that makes sense.

Any suggestions? I'm sure this can probably be done through repmat() somehow, but I can't figure it out. Thanks in advance!