Can we Generate a Random Matrix with No Repeated Elements
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kareem Elgindy
le 8 Nov 2022
Commenté : Kareem Elgindy
le 8 Nov 2022
I'm aware of randperm, but it gives vectors rather than 2D matrices. One may also use a loop with randperm to generate a random matrix with no repeated elements in each row, but overalll, this doesn't guarantee the non-redundancy of any element if we consider the whole matrix.
Is there a way to do that?
0 commentaires
Réponse acceptée
Bruno Luong
le 8 Nov 2022
Just the reshape long vector returned by randperm
m = 3;
n = 2;
A = reshape(randperm(10,m*n), m, n)
3 commentaires
Bruno Luong
le 8 Nov 2022
Modifié(e) : Bruno Luong
le 8 Nov 2022
You can map them to anything you like by simple indexing, here is set s as example:
m = 3;
n = 2;
s = 101:110;
A = s(reshape(randperm(numel(s),m*n), m, n))
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!