List(Vecor) Generation
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Junjie Liao
il 8 Set 2019
Modificato: Andrei Bobrov
il 8 Set 2019
Can I generate list [1 2 3 2 3 4 3 4 5 4 5 6 ....] without for loop?
Thanks!
0 Commenti
Risposta accettata
madhan ravi
il 8 Set 2019
m=3; % pairs
n=4; % n combinations
reshape((0:n-1)+(1:m)',1,[])
1 Commento
madhan ravi
il 8 Set 2019
If you're using version prior to 2016b:
% last line would be
reshape(bsxfun(@plus,(0:n-1),(1:m)'),1,[])
Più risposte (2)
Andrei Bobrov
il 8 Set 2019
Modificato: Andrei Bobrov
il 8 Set 2019
m=3;
n=4;
T = 1:m*n;
out = ceil(T/m) + mod(T-1,m);
or
out = floor(T/n) + mod(T-1,m) + 1;
or
out = repmat(1:m,1,n) + repelem(0:n-1,m);
0 Commenti
Vedere anche
Categorie
Scopri di più su Dijkstra algorithm in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!