Varying Random Number Generator between a Range

Hello,
I am trying to vary a random number generator between a range of vectors, this is my code
ub =[1;1;2;2;2;2;2;2;2;2];
lb =[0.95;0.96;1.88;1.88;1.85;1.85;1.75;1.75;1.65;1.58]
Y = lb + (ub-lb).*rand(10,1)
The result I am getting is a 10x4 double matrix, I want a 10x1 vector.
What changes I should make?

답변 (1개)

KSSV
KSSV 2020년 9월 3일

0 개 추천

lb = [750,150,8,8];
ub = [850,250,15,15];
%
id1 = randperm(length(lb),1) ; % select 1 lb randomly
id2 = randperm(length(ub),1) ; % select 1 ub randomly
Y = lb(id1) + (ub(id2)-lb(id1))*rand(10,1)

댓글 수: 6

Hi,
thanks for the answer :)
But I want to vary the Y such that the first integer is varying from 850 to 750, the second from 150 to 250, the third from 8 to 15.
Is there any way?
Stephen23
Stephen23 2020년 9월 3일
편집: Stephen23 2020년 9월 3일
"...I want to vary the Y such that the first integer is varying from 850 to 750, the second from 150 to 250, the third from 8 to 15."
That defines the first three values. What about the other seven? (you wrote that you "want a 10x1 vector").
And what is the range of 5th, 6th ... 10th random numbers? You give 4 bounds but then you want to generate 10 numbers. You need to be more coherent here.
Hi,
sorry for that confusion, I have edited the question :)
Great so now what is the size of Y?
You just answer your own question I think.
yeap, I guess :)

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2020년 9월 3일

댓글:

2020년 9월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by