Azzera filtri
Azzera filtri

How to generate random integer from 1 to N except some integers in between?

19 visualizzazioni (ultimi 30 giorni)
Suppose I want to generate unrepeated M integers between 1 and N. but except an arbitrary integer b s.t 1<= b<=N
is there any one-line command or something or do I have to construct a loop?

Risposta accettata

Matt J
Matt J il 18 Feb 2020
Modificato: Matt J il 18 Feb 2020
No loops required,
N=10; b=3; M=5; %example data
selection=list(randperm(N-1,M)) %result

Più risposte (0)


Scopri di più su Creating and Concatenating Matrices 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!

Translated by