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:
expanding matrix while copying elements

Subject: expanding matrix while copying elements

From: Bruce Bowler

Date: 19 Mar, 2013 15:40:33

Message: 1 of 4

Howdy. I know I can do this with a couple of loops, but that just feels
wrong...

I have a MxN matrix that I want to turn into a 12Mx12N matrix, filling in
the intermediate elements. Here's a brief example - Suppose the initial
matrix is 2x3 and I want to end up with 4x6

This 1 2 3 should end up as this 1 1 2 2 3 3
     4 5 6 1 1 2 2 3 3
                                   4 4 5 5 6 6
                                   4 4 5 5 6 6

TIA,
Bruce

Subject: expanding matrix while copying elements

From: Josh Meyer

Date: 19 Mar, 2013 15:59:30

Message: 2 of 4

You can use the kronecker tensor product function, 'kron', to do this. It
multiplies the second array by each element of the first array to produce
'blocks', then constructs a large matrix out of those blocks.

For example,

X = [1 2 3;4 5 6];
Y = kron(X,ones(2,2))

Y =

     1 1 2 2 3 3
     1 1 2 2 3 3
     4 4 5 5 6 6
     4 4 5 5 6 6

for more information,
http://www.mathworks.com/help/matlab/ref/kron.html

-Josh Meyer
josh.meyer@mathworks.com
"Bruce Bowler" <bbowler@bigelow.org> wrote in message
news:aqrf7gF2hv4U1@mid.individual.net...
> Howdy. I know I can do this with a couple of loops, but that just feels
> wrong...
>
> I have a MxN matrix that I want to turn into a 12Mx12N matrix, filling in
> the intermediate elements. Here's a brief example - Suppose the initial
> matrix is 2x3 and I want to end up with 4x6
>
> This 1 2 3 should end up as this 1 1 2 2 3 3
> 4 5 6 1 1 2 2 3 3
> 4 4 5 5 6 6
> 4 4 5 5 6 6
>
> TIA,
> Bruce

Subject: expanding matrix while copying elements

From: Bruce Bowler

Date: 19 Mar, 2013 16:16:20

Message: 3 of 4

Perfect, thanks!

On Tue, 19 Mar 2013 11:59:30 -0400, Josh Meyer wrote:

> You can use the kronecker tensor product function, 'kron', to do this.
> It multiplies the second array by each element of the first array to
> produce 'blocks', then constructs a large matrix out of those blocks.
>
> For example,
>
> X = [1 2 3;4 5 6];
> Y = kron(X,ones(2,2))
>
> Y =
>
> 1 1 2 2 3 3 1 1 2 2 3 3 4
> 4 5 5 6 6 4 4 5 5 6 6
>
> for more information,
> http://www.mathworks.com/help/matlab/ref/kron.html
>
> -Josh Meyer josh.meyer@mathworks.com "Bruce Bowler"
> <bbowler@bigelow.org> wrote in message
> news:aqrf7gF2hv4U1@mid.individual.net...
>> Howdy. I know I can do this with a couple of loops, but that just
>> feels wrong...
>>
>> I have a MxN matrix that I want to turn into a 12Mx12N matrix, filling
>> in the intermediate elements. Here's a brief example - Suppose the
>> initial matrix is 2x3 and I want to end up with 4x6
>>
>> This 1 2 3 should end up as this 1 1 2 2 3 3
>> 4 5 6 1 1 2 2 3 3
>> 4 4 5 5 6 6 4 4 5 5 6 6
>>
>> TIA,
>> Bruce

Subject: expanding matrix while copying elements

From: Bruno Luong

Date: 19 Mar, 2013 19:59:16

Message: 4 of 4

I have derived 4 different methods here
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326075

Have fun

Bruno

Tags for this Thread

No tags are associated with 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