Generate a vector like [5,4,4,3,3​,3,2,2,2,2​,1,1,1,1,1​]

1 Ansicht (letzte 30 Tage)
Izan Segarra
Izan Segarra am 19 Feb. 2019
Kommentiert: Guillaume am 20 Feb. 2019
How can I generate a vector like [5,4,4,3,3,3,2,2,2,2,1,1,1,1,1] without a loop?
  5 Kommentare
Izan Segarra
Izan Segarra am 19 Feb. 2019
I have used this code: odds = repelem([5,4,3,2,1],[1:5]);
It's just what I was looking for. Thank you.
Guillaume
Guillaume am 20 Feb. 2019
The square brackets are unnecessary.
odds = repelem(5:-1:1, 1:5)

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by