필터 지우기
필터 지우기

Can we Generate a Random Matrix with No Repeated Elements

조회 수: 2 (최근 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
Bruno Luong
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))
A = 3×2
109 107 105 104 110 102

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by