obtaining random data in cell array

in the attachment i have imported an excel data sheet containing a column of 100 english nouns. i then imported the data interactively and can be found in the workspace as a cell array with the value of 100x1, named 'nouns'. i am just wondering how i can generate a random integer between 1 and 100 that can choose any one of these words from the data (in short, randomly picking any word from the list of nouns in the workspace).
eventually the objective is to create a hangman game displayed in the image
thanks!

댓글 수: 2

Stephen23
Stephen23 2017년 10월 26일
편집: Stephen23 2017년 10월 26일
Not enough information. What does "i have a 100x1 cell made up of 100 words in each cell" really mean? Are the words stored in a string, or a char vector as natural language sentences, or a char matrix with one word per row padded with spaces, or a cell array of individual words, or something else?
Rather than trying to explain how the data is arranged, it would be much simpler if you simply uploaded the data for us to look at. Or something that is similar enough and has the same features as your data.
Simply edit your question and click the paperclip button to upload the data.
Brigham Tukukino
Brigham Tukukino 2017년 10월 27일
thanks stephen, i have updated the question. look forward to your reply

댓글을 달려면 로그인하십시오.

답변 (3개)

Jan
Jan 2017년 10월 26일

0 개 추천

randi([1,100], 1)
or simpler
randi(100)
Image Analyst
Image Analyst 2017년 10월 27일

0 개 추천

Try this, which is robust as to the number of words in your workbook
% Read words from the Excel file.
[~, words] = xlsread(xlfileName);
% Get the index of a random word to use. Does not assume 100 - can be any length!
randomIndex = randi(size(words, 1));
% Get the actual word (extract it into a string from the cell).
wordToUse = strings{randomIndex};

카테고리

도움말 센터File Exchange에서 Text Data Preparation에 대해 자세히 알아보기

질문:

2017년 10월 26일

답변:

2017년 10월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by