Copying a matrix into another larger matrix multiple times

6 visualizaciones (últimos 30 días)
Olu adroit
Olu adroit el 12 de En. de 2016
Editada: Stephen23 el 12 de En. de 2016
Hi all, I am trying to write a script that creates a larger matrix B from a smaller matrix A = [1;1;1;2;2;2;3;3;3;4;4;4] whereby A is copied into B in N times. E.g if N = 4, B = [1;1;1;2;2;2;3;3;3;4;4;4;1;1;1;2;2;2;3;3;3;4;4;4;1;1;1;2;2;2;3;3;3;4;4;4;1;1;1;2;2;2;3;3;3;4;4;4]. Thank you for your help in advance.
Adroit

Respuesta aceptada

Stephen23
Stephen23 el 12 de En. de 2016
Editada: Stephen23 el 12 de En. de 2016
You don't need to reinvent the wheel using slow and inefficient nested loops, just use repmat:
>> A = [1,2,3,4];
>> B = repmat(A(:),4,1)
B =
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4
>> BB = repmat({A},4,4);
If a cell contains an array with more than one element, then it shows a summary of that array:
>> X = {5}
X =
[5]
>> X = {5:6}
X =
[1x2 double]
but the data is still all there!:
>> X{1}
ans = 5 6

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by