필터 지우기
필터 지우기

generate pair numbers randomly

조회 수: 12 (최근 30일)
ananaya
ananaya 2022년 7월 11일
댓글: Image Analyst 2022년 7월 11일
I want to pair two numbers randomly in each pair as [ 5 8] [ 11 4] [3 17] .....
  댓글 수: 1
Image Analyst
Image Analyst 2022년 7월 11일
Are repeats, either in the same row or in different rows, allowed? Or do all numbers need to be different? Must the numbers be integers, or can they be floating point/fractional?
Is this homework?

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

답변 (2개)

Hrusheekesh
Hrusheekesh 2022년 7월 11일
hi ananya,
it is my understanding that you want to create a array of pairs with random vaues. but is there any constraints like the range or max value.
anyways if there is a value try this
a=20;
idx=reshape(randperm(a,[],2);

KSSV
KSSV 2022년 7월 11일
Say you want to pair numbers randomly between 1 to 20.
n = 10 ;
iwant = zeros(n,2) ;
for i = 1:n
iwant(i,:) = randperm(20,2) ;
end
iwant
iwant = 10×2
11 8 16 14 8 1 20 18 11 6 6 20 4 18 15 14 5 3 18 2

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by