copying the contents of a vector onto a longer vector

1 vue (au cours des 30 derniers jours)
cgo
cgo le 25 Juil 2022
Réponse apportée : Chunru le 25 Juil 2022
Let's say I have a vector a that is of size 4. I have a vector b of size 10. I want to copy the contents of vector a into b until it 'runs out'.
For example: if a = [1 2 3 4]; and b is a size 10 vector.
Then b = [1 2 3 4 1 2 3 4 1 2].
How do i do this?

Réponse acceptée

Chunru
Chunru le 25 Juil 2022
a = [1 2 3 4];
b = a(mod(0:9, 4)+1)
b = 1×10
1 2 3 4 1 2 3 4 1 2

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by