MATLAB: I have row vector r=[1 2 3 4 5 6 7 8 9 10] and from this i generate another row vector of size 4 that is z=randperm(10,4) now i want to randomly select a single element from remaining element of r.

randperm

r=[1 2 3 4 5 6 7 8 9 10]; z=randperm(10,4);

Best Answer

r = 1:10;
z = randperm(numel(r),4);
y = setdiff(r,z);
out = y(randi(numel(y),1));