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]));
Therandperm function is another option if you have a vector of non-duplicating numbers and you want the perumtations of it.
This sound like homework, but since there’s a chance it could be part of a legitimate research problem, this is how I would do it:
M = zeros(50,28);
for k1 = 1:50
M(k1,randperm(28,14)) = 1;
end
Sample = M(1:5,:) % Look At First Five Rows
The code begins by preallocating the‘M’ matrix, then assigning random, non-repeating (in the same row vector)1 values to each row. See the documentation forrandperm for details.
Best Answer