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:
select a name at random from a list of names

Subject: select a name at random from a list of names

From: Namo

Date: 1 Mar, 2011 08:46:08

Message: 1 of 2

I have a text file that has a list of names and I want to select a name at random from this list.

I want the names to flash in a screen one after another; then stop at one name at random (the same method is shown to draw a lot in some TV shows)

Subject: select a name at random from a list of names

From: Jos (10584)

Date: 1 Mar, 2011 11:33:40

Message: 2 of 2

"Namo " <namo1983@hotmail.com> wrote in message <ikibog$pv8$1@fred.mathworks.com>...
> I have a text file that has a list of names and I want to select a name at random from this list.
>
> I want the names to flash in a screen one after another; then stop at one name at random (the same method is shown to draw a lot in some TV shows)

To give you a starting point:

* Step 1: load the names into a cell array
see, for instance, TEXTREAD

You will have a cell array like this
Names = {'Joe','Bob','John','Bill'}

* Step 2:
loop a certain amount of times, displaying a random names each time

for ...
   % select a random name
   idx = randi(numel(Names),1) ;
   currentName = Names{idx}
   % display
end

see, FOR, DISP, RANDI, RANDSAMPLE, etc.

~ Jos

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