How to generate sequences from two vectors using rowfun
Afficher commentaires plus anciens
Hi,
I am trying to generate sequences for which starting values and last values+1 are contained in vectors, without using for-loop. Because there is a lot of data to process, doing for-loop is unfortunately not feasible. As the output, I want to have all the sequences to be concatenated into one vector. I think rowfun can help me here, but so far I have not been successful. If someone can give me a helping hand, I would be grateful.
This is an example;
x = [1,6,12]'; y = [5,10,13]';
the output I wish to obtain: z = [1,2,3,4,6,7,8,9,12];
I imagine it should be something like;
inputvecs = table(x,y);
z = rowfun(@seqgen,inputvecs)
How should the function seqgen look in this case? Should concatenation within the function?
Thank you very much for your help.
Etsuko
Réponse acceptée
Plus de réponses (1)
Andrei Bobrov
le 13 Juil 2016
Modifié(e) : Andrei Bobrov
le 13 Juil 2016
x = [1,6,12]; y = [5,10,13];
a = (min(x):max(y))';
[ii,~] = find(bsxfun(@ge,a,x)&bsxfun(@lt,a,y));
out = a(ii);
1 commentaire
Etsuko
le 13 Juil 2016
Catégories
En savoir plus sur ARM Cortex-A Processors dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!