Can we Generate a Random Matrix with No Repeated Elements

4 ビュー (過去 30 日間)
Kareem Elgindy
Kareem Elgindy 2022 年 11 月 8 日
コメント済み: Kareem Elgindy 2022 年 11 月 8 日
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?

採用された回答

Bruno Luong
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)
A = 3×2
7 10 1 4 2 6
  3 件のコメント
Kareem Elgindy
Kareem Elgindy 2022 年 11 月 8 日
Fantastic!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Find more on Random Number Generation in Help Center and File Exchange

タグ

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by