From: Yaquan Xu on
I have a question about matrix manipulation, I am not very familiar with matlab code and I am trying to expand a matrix by repeating the numbers.

Here is the example.

I have a 4 by 4 matrix as follow:

0 5 2 3
5 0 1 4
2 1 0 5
3 4 5 0

Now i try to expand this matrix to 8 by 8 matrix as follow:

0 0 5 0 2 0 3 0
0 0 0 5 0 2 0 3
5 0 0 0 1 0 4 0
0 5 0 0 0 1 0 4
2 0 1 0 0 0 5 0
0 2 0 1 0 0 0 5
3 0 4 0 5 0 0 0
0 3 0 4 0 5 0 0

Please help.Thanks in advance.
From: Bruno Luong on
>> A=[0 5 2 3
5 0 1 4
2 1 0 5
3 4 5 0]

A =

0 5 2 3
5 0 1 4
2 1 0 5
3 4 5 0

>> kron(A,[1 0; 0 1])

ans =

0 0 5 0 2 0 3 0
0 0 0 5 0 2 0 3
5 0 0 0 1 0 4 0
0 5 0 0 0 1 0 4
2 0 1 0 0 0 5 0
0 2 0 1 0 0 0 5
3 0 4 0 5 0 0 0
0 3 0 4 0 5 0 0

% Bruno
From: Yaquan Xu on
Thank you so much. It really solved my problem!

"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hni4se$ot2$1(a)fred.mathworks.com>...
> >> A=[0 5 2 3
> 5 0 1 4
> 2 1 0 5
> 3 4 5 0]
>
> A =
>
> 0 5 2 3
> 5 0 1 4
> 2 1 0 5
> 3 4 5 0
>
> >> kron(A,[1 0; 0 1])
>
> ans =
>
> 0 0 5 0 2 0 3 0
> 0 0 0 5 0 2 0 3
> 5 0 0 0 1 0 4 0
> 0 5 0 0 0 1 0 4
> 2 0 1 0 0 0 5 0
> 0 2 0 1 0 0 0 5
> 3 0 4 0 5 0 0 0
> 0 3 0 4 0 5 0 0
>
> % Bruno
From: Matt J on
"Yaquan Xu" <yaquanxu(a)gmail.com> wrote in message <hni6u4$pb2$1(a)fred.mathworks.com>...
> Thank you so much. It really solved my problem!

But you might want to explain a bit what you need this for.
It's important to point out that one rarely needs to explicitly expand a matrix using
kron(A,B), as you're doing. It's usually much more efficient to work with A and B separately, which is why I made this tool:

http://www.mathworks.com/matlabcentral/fileexchange/25969-efficient-object-oriented-kronecker-product-manipulation
From: Yaquan Xu on
Thank you so much. It really solved my problem!

"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hni4se$ot2$1(a)fred.mathworks.com>...
> >> A=[0 5 2 3
> 5 0 1 4
> 2 1 0 5
> 3 4 5 0]
>
> A =
>
> 0 5 2 3
> 5 0 1 4
> 2 1 0 5
> 3 4 5 0
>
> >> kron(A,[1 0; 0 1])
>
> ans =
>
> 0 0 5 0 2 0 3 0
> 0 0 0 5 0 2 0 3
> 5 0 0 0 1 0 4 0
> 0 5 0 0 0 1 0 4
> 2 0 1 0 0 0 5 0
> 0 2 0 1 0 0 0 5
> 3 0 4 0 5 0 0 0
> 0 3 0 4 0 5 0 0
>
> % Bruno