Thread Subject: How to randomly selet a name from a list a of 47 names?

Subject: How to randomly selet a name from a list a of 47 names?

From: Van

Date: 12 Nov, 2009 22:29:15

Message: 1 of 5

I need to write a code for making a random selection from a list of 47 non number data.

I have made a data file listing all the data and am aware of the function textscan. But I am not getting it to work.

Also, how do I call for a random data that is in the list?

Thanks


Message was edited by: Van

Subject: How to randomly selet a name from a list a of 47 names?

From: Jomar Bueyes

Date: 12 Nov, 2009 22:50:52

Message: 2 of 5

On Nov 12, 5:29 pm, Van <sw_kni...@hotmail.com> wrote:
> I need to write a code for making a random selection from a list of 47 non number data.
>
> I have made a data file listing all the data and am aware of the function textscan. But I am not getting it to work.
>
> Also, how do I call for a random data that is in the list?
>
> Thanks
>
> Message was edited by: Van

Place the list in a cell array with 47 elements. Generate an integer
random number in the range [1, 47]. Use the random number as the index
to the cell array to retrieve the corresponding name.

HTH

Jomar

Subject: How to randomly selet a name from a list a of 47 names?

From: Camron Call

Date: 12 Nov, 2009 23:06:01

Message: 3 of 5

Van <sw_knight@hotmail.com> wrote in message <482182665.7784.1258064993439.JavaMail.root@gallium.mathforum.org>...
> I need to write a code for making a random selection from a list of 47 non number data.
>
> I have made a data file listing all the data and am aware of the function textscan. But I am not getting it to work.
>
> Also, how do I call for a random data that is in the list?
>
> Thanks
>
>
> Message was edited by: Van
--------------------------------------------------------------------------------------------

%Put the names into a cell array.

a ={'Name1';'Name2';'Name3';'Name4';'Name5'};

%Then use the uniform random distruibution (rand) as the index

randomname = a(round(rand*length(a)));

Subject: How to randomly selet a name from a list a of 47 names?

From: Camron Call

Date: 12 Nov, 2009 23:12:03

Message: 4 of 5

I was too slow!

Subject: How to randomly selet a name from a list a of 47 names?

From: Van

Date: 13 Nov, 2009 00:02:33

Message: 5 of 5

No problem!!... thanks for the replies :D Got it working ^^

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com