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

24 次查看(过去 30 天)
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?
Thanks

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by