repeating an index number n times in a vector
Ältere Kommentare anzeigen
Hi People,
I'd like to transform a vector p like this one. p=[3 0 2 2 1 0 3]
Into a new vector that has n times the indexnumber of n, for example:
new vector: v=[1 1 1 3 3 4 4 5 7 7 7] so it has 3 times 1, zero times 2, 2 times 3 and so on.
the numbers generated in p are variable but are always between 0 and 15
I hope you can help me.
Regards, Siem
Akzeptierte Antwort
Weitere Antworten (1)
Chris
am 23 Jan. 2014
Hey Siem,
I would do it like this:
v = p .* 1:length(p);
1 Kommentar
Siem Nijskens
am 23 Jan. 2014
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!