Can we Generate a Random Matrix with No Repeated Elements
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Bruno Luong
2022-11-8
Just the reshape long vector returned by randperm
m = 3;
n = 2;
A = reshape(randperm(10,m*n), m, n)
3 个评论
Bruno Luong
2022-11-8
编辑:Bruno Luong
2022-11-8
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))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!