selecting random part of string
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Max
am 7 Nov. 2015
Bearbeitet: Geoff Hayes
am 7 Nov. 2015
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
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 7 Nov. 2015
Bearbeitet: Geoff Hayes
am 7 Nov. 2015
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!