Generating a random matrix with range

조회 수: 9 (최근 30일)
Melwin Thomas
Melwin Thomas 2018년 6월 5일
댓글: Melwin Thomas 2018년 6월 5일
Hi,
I am trying to generate 12*2 matrix. The first column should contain random values between [0 5] and the second column should have random values between [5 20]. Can you help me out with this.

채택된 답변

Kodavati Mahendra
Kodavati Mahendra 2018년 6월 5일
May be something crude like this?
x = rand(12,2);
x(:,1) = 5*x(:,1);
x(:,2) = 5+15*x(:,2)
rand generates uniformly distributed random number in the interval (0,1).
  댓글 수: 3
Melwin Thomas
Melwin Thomas 2018년 6월 5일
Thank you very much. Appreciate your help. It works. I made it a little complicated
a = [0:5]; b = [5:20];
for x=1:12
m = zeros(1:2);
V = repmat([(5.*rand(a)); (5+(20-5).*rand(b))],6);
end
disp(V)
Thank you.
Melwin Thomas
Melwin Thomas 2018년 6월 5일
That's why I was not able to figure it out. Anyways thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by