MATLAB: Prevent repeating number in a vector

vectors

Hi all, If I have any random matrix: [2 4 5 6 4] The number 4 is repeated here. I would like some help in being able to prevent this repeating. your help is appreciated. Hany

Best Answer

I am not certain what you want.
If you want a random matrix that prevents repeats, this works:
M = perms(unique([2 4 5 6 4]));
The randperm function is another option if you have a vector of non-duplicating numbers and you want the perumtations of it.