Modifying a matrix such that each entry can be written in a block of four

1 visualización (últimos 30 días)
Hi,
I have a matrix, say
A = [1 2
3 4];
I want to modify it in such a way that it can be written as
A = [1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4];
Each entry in the matrix A can be written in a block of four. How can I code it?

Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de Sept. de 2021
Editada: Walter Roberson el 6 de Sept. de 2021
A = [1 2
3 4]
A = 2×2
1 2 3 4
B = kron(A, ones(2,2))
B = 4×4
1 1 2 2 1 1 2 2 3 3 4 4 3 3 4 4
C = repelem(A, 2, 2)
C = 4×4
1 1 2 2 1 1 2 2 3 3 4 4 3 3 4 4

Más respuestas (1)

Yamina chbak
Yamina chbak el 6 de Sept. de 2021
a=[1 2 ; 3 4];
A=zeros(2*size(a));
A(1:2,1:2)=a(1);
A(1:2,3:4)=a(3);
A(3:4,1:2)=a(2);
A(3:4,3:4)=a(4);
A
A = 4×4
1 1 2 2 1 1 2 2 3 3 4 4 3 3 4 4

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by