selecting random part of string

say I have
alphabet='abcdefghijklmnopqrstuvwxyz'
how do i select a random letter from the alphabet so Guess= random letter from alphabet and once I have selected a random letter from the alphabet, then remove that letter from the alphabet.
Thank you

 採用された回答

Geoff Hayes
Geoff Hayes 2015 年 11 月 7 日
編集済み: Geoff Hayes 2015 年 11 月 7 日

0 投票

Max - use randperm to generate a random index into your character array. Try the following
alphabet = 'abcdefghijklmnopqrstuvwxyz';
randIdx = randperm(length(alphabet),1); % generate the random index into array
randChar = alphabet(randIdx); % get the random character
alphabet(randIdx) = []; % remove the character
For example, if
randIdx =
14
then
randChar =
n
and
alphabet =
abcdefghijklmopqrstuvwxyz
with the 'n' removed.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

質問済み:

Max
2015 年 11 月 7 日

編集済み:

2015 年 11 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by