Can we Generate a Random Matrix with No Repeated Elements
3 ビュー (過去 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!