MATLAB: How to create a random matrix with no duplicate value in the line

matrixrandom

I want to create a random matrix with no duplicate value in every line of the matrix

Best Answer

Use randperm to get a sequence of integers with no repetitions:
>> randperm(9)
ans =
9 6 5 8 3 7 1 4 2
If you want a matrix where each row has unique numbers, then you can use a loop:
R = 3;
C = 5;
mat = NaN(R,C);
for k = 1:R
mat(k,:) = randperm(C);
end
which gives:
>> mat
mat =
3 4 1 5 2
4 1 2 5 3
4 5 2 1 3