Selecting words in MATLAB
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Andrew Newell
am 4 Feb. 2011
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.
Antworten (3)
Matt Fig
am 29 Jan. 2011
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
>>
2 Kommentare
Jiro Doke
am 1 Feb. 2011
What defines a "meaningful sentence"? Can it be represented by some logic? Then you can program it just like what Matt did, except you would replace "ceil(rand*3)" with the appropriate logic.
Andrew Newell
am 29 Jan. 2011
If your goal is to search for a given string in a cell array, you can use strcmp.
0 Kommentare
Jiro Doke
am 30 Jan. 2011
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu String Parsing 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!