Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
generating 2 numbers..

Subject: generating 2 numbers..

From: asma khalid

Date: 10 Nov, 2010 23:00:06

Message: 1 of 11

I want to generate 2 number say x and y where x<y. How do i do that?

Subject: generating 2 numbers..

From: Sean

Date: 10 Nov, 2010 23:11:03

Message: 2 of 11

"asma khalid" <asma_167@hotmail.com> wrote in message <ibf85m$r4g$1@fred.mathworks.com>...
> I want to generate 2 number say x and y where x<y. How do i do that?

A = rand(1,2);
x = min(A);
y = max(A);

Subject: generating 2 numbers..

From: Matt Fig

Date: 10 Nov, 2010 23:13:04

Message: 3 of 11

One of you many many ways to do this.

y = rand(1,2);
x = min(y)
y = y(y~=x)

Subject: generating 2 numbers..

From: John D'Errico

Date: 10 Nov, 2010 23:14:04

Message: 4 of 11

"asma khalid" <asma_167@hotmail.com> wrote in message <ibf85m$r4g$1@fred.mathworks.com>...
> I want to generate 2 number say x and y where x<y. How do i do that?

No problem.

x = 2;
y = 3;

If your goal is something more sophisticated, then
you need to define your needs more accurately.

John

Subject: generating 2 numbers..

From: Walter Roberson

Date: 10 Nov, 2010 23:55:10

Message: 5 of 11

On 10-11-10 05:00 PM, asma khalid wrote:
> I want to generate 2 number say x and y where x<y. How do i do that?


x = rand;
y = (x + rand) ./ 2;
x = x ./ 2;

Subject: generating 2 numbers..

From: asma khalid

Date: 11 Nov, 2010 12:22:03

Message: 6 of 11

Im sorry John. What i meant was that I want to generate two random numbers x and y where x should be less than y.


"John D'Errico" <woodchips@rochester.rr.com> wrote in message <ibf8vs$k7m$1@fred.mathworks.com>...
> "asma khalid" <asma_167@hotmail.com> wrote in message <ibf85m$r4g$1@fred.mathworks.com>...
> > I want to generate 2 number say x and y where x<y. How do i do that?
>
> No problem.
>
> x = 2;
> y = 3;
>
> If your goal is something more sophisticated, then
> you need to define your needs more accurately.
>
> John

Subject: generating 2 numbers..

From: asma khalid

Date: 11 Nov, 2010 12:29:04

Message: 7 of 11

Thank You Sean. If I need 10 such random numbers x and y such that x<y how should i do that.

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ibf8q7$9b8$1@fred.mathworks.com>...
> "asma khalid" <asma_167@hotmail.com> wrote in message <ibf85m$r4g$1@fred.mathworks.com>...
> > I want to generate 2 number say x and y where x<y. How do i do that?
>
> A = rand(1,2);
> x = min(A);
> y = max(A);

Subject: generating 2 numbers..

From: Sean

Date: 11 Nov, 2010 12:56:05

Message: 8 of 11

"asma khalid" <asma_167@hotmail.com> wrote in message <ibgnig$khe$1@fred.mathworks.com>...
> Thank You Sean. If I need 10 such random numbers x and y such that x<y how should i do that.
>
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ibf8q7$9b8$1@fred.mathworks.com>...
> > "asma khalid" <asma_167@hotmail.com> wrote in message <ibf85m$r4g$1@fred.mathworks.com>...
> > > I want to generate 2 number say x and y where x<y. How do i do that?
> >
> > A = rand(1,2);
> > x = min(A);
> > y = max(A);

A = sort(rand(10,2),2); %data
x = A(:,1); %smaller column
y = A(:,2); %bigger column

%Insure results
all(x<y)

Subject: generating 2 numbers..

From: asma khalid

Date: 23 Nov, 2010 21:04:04

Message: 9 of 11

Dear Sean,
Thank you for your help. I am working in interval analysis. when i use the following program in my work, i get an interval ...and what i claim in my work is that my interval best represents the 3 voter's intervals. now the problem is that since my generated A is a random interval, every time my instructor runs it , he gets a different answer. i want the program to run once...i should get the answers and apply my theory on them.. and then when anyone runs it again it should give the same intervals... could you help me with this ..i hope i have made my question clear.
A = rand(1,2);

> > x = min(A);

> > y = max(A);



A = sort(rand(10,2),2); %data

x = A(:,1); %smaller column

y = A(:,2); %bigger column






"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ibf8q7$9b8$1@fred.mathworks.com>...
> "asma khalid" <asma_167@hotmail.com> wrote in message <ibf85m$r4g$1@fred.mathworks.com>...
> > I want to generate 2 number say x and y where x<y. How do i do that?
>
> A = rand(1,2);
> x = min(A);
> y = max(A);

Subject: generating 2 numbers..

From: Sean de

Date: 23 Nov, 2010 21:31:06

Message: 10 of 11

"asma khalid" <asma_167@hotmail.com> wrote in message <icha84$meh$1@fred.mathworks.com>...
> Dear Sean,
> Thank you for your help. I am working in interval analysis. when i use the following program in my work, i get an interval ...and what i claim in my work is that my interval best represents the 3 voter's intervals. now the problem is that since my generated A is a random interval, every time my instructor runs it , he gets a different answer. i want the program to run once...i should get the answers and apply my theory on them.. and then when anyone runs it again it should give the same intervals... could you help me with this ..i hope i have made my question clear.
> A = rand(1,2);
>
> > > x = min(A);
>
> > > y = max(A);
>
>
>
> A = sort(rand(10,2),2); %data
>
> x = A(:,1); %smaller column
>
> y = A(:,2); %bigger column
>
>

Your explanation is not clear to me. You want the same numbers every time but you want it to be random? If so then you have to reseed the random number generator every time it is called. For example: you could seed it to 1 or pi, and then it'll generate the same random numbers every time. It would be just as easy for you to generate 20 random numbers and then hardwire them in your function, like what John suggested.

Subject: generating 2 numbers..

From: asma khalid

Date: 24 Nov, 2010 19:20:05

Message: 11 of 11

Yes, I want to generate random numbers and i want the same numbers to appear every time i run my program. my actual work is dealing with 1000 random numbers ....i think i could save the result in an m-file and call it when i work on it further..




> > Dear Sean,
> > Thank you for your help. I am working in interval analysis. when i use the following program in my work, i get an interval ...and what i claim in my work is that my interval best represents the 3 voter's intervals. now the problem is that since my generated A is a random interval, every time my instructor runs it , he gets a different answer. i want the program to run once...i should get the answers and apply my theory on them.. and then when anyone runs it again it should give the same intervals... could you help me with this ..i hope i have made my question clear.
> > A = rand(1,2);
> >
> > > > x = min(A);
> >
> > > > y = max(A);
> >
> >
> >
> > A = sort(rand(10,2),2); %data
> >
> > x = A(:,1); %smaller column
> >
> > y = A(:,2); %bigger column
> >
> >
>
> Your explanation is not clear to me. You want the same numbers every time but you want it to be random? If so then you have to reseed the random number generator every time it is called. For example: you could seed it to 1 or pi, and then it'll generate the same random numbers every time. It would be just as easy for you to generate 20 random numbers and then hardwire them in your function, like what John suggested.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us