Repeating elements of an array
98 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Say
for some
. How can I create an array of size
which is just
i.e repeat the elements of x M times each in a row.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/822960/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/822965/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/822970/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/822975/image.png)
Note I have tried using the reshape function but cant work out how to do it in this case.
1 Commento
James Tursa
il 3 Dic 2021
What have you done so far? What specific problems are you having with your code?
Risposte (1)
Dave B
il 3 Dic 2021
repelem is good for repeating an element n times, so I think this is what you want. Here I repeat the numbers in a 3 times each:
a=[1 3 7 9];
repelem(a,3)
repmat is good when you want to repeat an array of elements, here I repeat a itself 3 times in the row dimension, and 2 times in the column dimension:
repmat(a,3,2)
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrix Indexing 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!