How to input letters into an array?
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I am working on a project for a class I have making a Hangman game. I am trying to input guessed letters into a blank array, but when they are inputted, they show up as the number associated with each letter.
Here is the code I am using:
letters = ismember(word,guess); %letters is a logical array with 1s where the guess, a single letter, is in the word
word_display(letters == 1 ) = guess; %where letters==1, guess is inputted into word display, a zeros array with length of the word.
How do I make it where the word_display displays the letters and not their number that is given them by MATLAB
Thanks!
0 个评论
回答(1 个)
Walter Roberson
2017-3-14
Start with
word_display = blanks(length(word));
then at each iteration
[letters, idx] = ismember(word,guess);
word_display(letters) = guess;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!