Selecting words in MATLAB
古いコメントを表示
I am trying to code a MATLAB program where I have to select a word from a group of 150 words divided into three groups of 50 words each. I know I need to apply some sorting and searching, but I don't know how to go about it in MATLAB.
3 件のコメント
Andrew Newell
2011 年 1 月 29 日
It is still not clear what you want to do. Are you given a word or more and then required to search for it in the array? Does the array need to be 3-by-50, or could it simply be 1-by-150? Do you know what the "meaningful sentence" is in advance or does the program have to construct it?
John
2011 年 1 月 30 日
Andrew Newell
2011 年 2 月 4 日
Sorry for the delay in replying. So in Matt's example below, if the eye responses are {left, right, both}, then the program must form a phrase with one word from A followed by one word from B followed by one word from C?
If I understand you right, the computer must decide which of 'Help wow rent', 'Keep her true', etc., is meant by the user. In your problem, there are 50 words/phrases per group and therefore 50^3 possible combinations.
回答 (3 件)
Matt Fig
2011 年 1 月 29 日
You don't say how the words are divided, or even what kind of selection is to be made. However, I will assume you have three cell arrays A,B,C. Like in this example, use RAND.
>> A = {'Help';'Keep';'love'};
>> B = {'wow';'her';'now'};
>> C = {'true';'sleep';'rent'};
>> word1 = A{ceil(rand*3)}
word1 =
love
>> word2 = B{ceil(rand*3)}
word2 =
wow
>> word3 = C{ceil(rand*3)}
word3 =
sleep
>>
Andrew Newell
2011 年 1 月 29 日
1 投票
If your goal is to search for a given string in a cell array, you can use strcmp.
Jiro Doke
2011 年 1 月 30 日
I understand what the goal of your application is, but it's still not clear on the specifics of how and what your want to "sort and search". In your comment above, you mention "first third", "second third", and "last third". With 150 words, that's pretty straight-forward:
firstThird = allWords(1:50);
secondThird = allWords(51:100);
lastThird = allWords(101:150);
For sorting, use the function sort. For searching for a specific word in a cell array, use the functions strcmp or strcmpi.
カテゴリ
ヘルプ センター および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!