Create a vector with block elements of the same value
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
For my superfast code (no element wise evaluation of collocation points, but vector-wise) to evaluate Uniform cubic B-splines, I am looking for an answer to the following question:
I wish to create a vector that should contain this N blocks of size k the same values (starting from 1,2,3...up to N). As an example:
suppose k=3 and N=3, I want: [1 1 1 2 2 2 3 3 3 ]
I should be quite an easy thing to do, but I just can figure it out how to do it. Hope you guys can help!
1 commentaire
Walter Roberson
le 9 Mar 2012
ndgrid() or meshgrid(), take a single output and reshape it to be a vector.
I do not have access at the moment to test the exact sequence.
Réponse acceptée
Plus de réponses (1)
Oleg Komarov
le 9 Mar 2012
Another approach, run-length decoding:
nk = n*k;
out = zeros(1,nk);
out(1:k:nk) = 1;
out = cumsum(out);
0 commentaires
Voir également
Catégories
En savoir plus sur Interpolation 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!