Info

此问题已关闭。 请重新打开它进行编辑或回答。

How can I create an updated true false array from inputting values through a word search? (via user defined functions)

1 次查看(过去 30 天)
Hello everyone,
So here is what I have, bear with me. I am creating a word search right now via user defined functions, almost like creating a game for Matlab. I have created the puzzle and inserted the words inside the word search according to their orientation and size. What I am having difficulty doing is printing the found words onto the main script.
If I print out the array called "theWords," it will give me a 10x1 cell array of a list of 10 words that are in the word search. What I want to create is a vector called foundWordsVector, which will be a 10x1 logical array that is composed of true values(1) or false values(0). This is updated every time the user inputs a new word. So for example, if I entered in 'Cookies' and that was part of the word search, it would show up as (vertical format): 0 0 0 0 1 0 0 0. I am unsure how to update this vector through loops. Also, at the end up the function, it should print: 'So far you have found the words: [word1, word2, etc...] but I am also unsure how to write this as well.
I understand this is a little unclear but I am completely stuck at this point. Let me know if you have any suggestions on what to do!
Thank you, Hackney
  1 个评论
James Tursa
James Tursa 2017-2-24
Could you write some short pseudo-code for us, along with a short complete example, of how you want things to work? I.e., "Here is a complete example ... given these inputs I would like this as an output"

回答(1 个)

Vandana Rajan
Vandana Rajan 2017-2-27
Hi,
I have made some code according to my understanding of your query.
wordlist = {'Office' 'Desk' 'PC' 'Chair' 'Pen' 'Card' 'Bottle' 'Mouse' 'Book' 'Marker'};
id = 1;
s = string([]);
while(id<=3)
inp_word = input('Enter the search word\n');
ind = zeros(1,numel(wordlist));
for i = 1:numel(wordlist)
ind(i) = isequal(inp_word,wordlist{i});
end
ind
disp('so far we have found the words');
s(id,1) = string(inp_word);
disp(s);
id = id+1;
end
Apart from this, 'string' function converts a cell to a string array. you may then use 'ismember' function to match the input string with the string array.
str = string(wordlist);
inp_word = 'PC';
[val,indx] = ismember(string(inp_word),str);

Community Treasure Hunt

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

Start Hunting!

Translated by