Boss_Bandor
Boss_Bandor

Reputation: 52

random integer in Matlab within a range but excluding values

I have generated random numbers in MATLAB within a range using the below:

N=10000;
n=3000;
c=randperm(N,n);

I need another set of random numbers within the same range 1:N and of the same size n but excluding the values in c. Any ideas?

Upvotes: 0

Views: 719

Answers (1)

m3tho
m3tho

Reputation: 602

You can use again randperm excluding the integers of array c to crate array d with same length n:

ok = 1:N;
ok(c) = [];
d=ok(randperm(numel(ok),n));

Upvotes: 4

Related Questions