# Copying a matrix into another larger matrix multiple times

1 visualizzazione (ultimi 30 giorni)
Olu adroit il 12 Gen 2016
Modificato: Stephen23 il 12 Gen 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.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Stephen23 il 12 Gen 2016
Modificato: Stephen23 il 12 Gen 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
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by