how to select name at random from list of names in text file?
1 view (last 30 days)
Show older comments
I have text file that has list of names, and I want to choose one name in the list at random.
I want the names to flash one after another and then stop at one name at random ( the same method that use to select winner at random on some TV shows).
1 Comment
Answers (1)
Matt Tearle
on 1 Mar 2011
General approach:
- Read the names from file into a cell array of strings -- see textscan
- Make a figure window with uicontrol textboxes
- Set the String property of each textbox to one of the strings in the cell array (ie names)
- Randomly select an integer from 1 to n (see randi)
- Change the color (or whatever property) of the chosen textbox
- Repeat some number of times, after a short pause
(Or cycle through in order, stopping at a random point, if you prefer.)
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!