How to create this monotonically increasing list of numbers?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dominik Mattioli
le 11 Juil 2018
Réponse apportée : Michiele Ogbagabir
le 11 Juil 2018
I want to use a vector V of length N
V = [1 1 2 1 2 3 1]
to create a monotonically increasing list L, where the values of L are as follows:
L = [1 2 3 3 4 5 5 6 6 6 7]
So the entries 1:N of V dictate how many times V(N) is listed sequentially in L,
i.e. the 1st entry in V is listed in L a total of V(1) times..., the nth entry of V is listed in L a total of V(n) times.
0 commentaires
Réponse acceptée
Plus de réponses (1)
Michiele Ogbagabir
le 11 Juil 2018
Here is one way
V = [ 1 1 2 1 2 3 1];
L = [];
for i = 1:length(V)
L = [L repelem(i, V(i))];
end
L
0 commentaires
Voir également
Catégories
En savoir plus sur Data Exploration dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!