How to select a one random letter from a matrix of letters.

I have the array.
move = [R ,P, S]
How would I select a random letter from this array.
cmove = ?
Would it look something like this ?:
cmove = move(rand(numel(move)))

 Accepted Answer

move = {'R' ,'P', 'S'}
cmove = move(randi(numel(move)))
or
move ='RPS'
cmove = move(randi(numel(move)))

2 Comments

is there a way to remove those quotation marks
You can find them without quotation in the workspace

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!