How can I generate a Matrix (4x4) with random different figures from 1 to 4 ?
Show older comments
Hello, How can I generate a Matrix (size 4x4) with random different figures from 1 to 4 ? Figures must be different in the lines and the columns. in example:
A=[1 2 3 4; 2 1 4 3; 3 4 1 2; 4 3 2 1]
thank you.
Accepted Answer
More Answers (1)
Andrei Bobrov
on 10 Apr 2013
Edited: Andrei Bobrov
on 17 Apr 2013
n = 4;
A = rem(bsxfun(@plus,1:n,(0:n-1)')-1,n)+1;
or [EDIT]
A = hankel(1:n,[n 1:n-1]);
A = A(randperm(n),:);
A = A(:,rendperm(n));
2 Comments
Lorenz
on 17 Apr 2013
Andrei Bobrov
on 17 Apr 2013
Edited: Andrei Bobrov
on 17 Apr 2013
see EDIT
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!