Selecting words in MATLAB

8 views (last 30 days)
John
John on 29 Jan 2011
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 Comments
John
John on 30 Jan 2011
Hi Andrew,I am working on a program that uses webcam to capture facial images to determine if either the left eye or the right eye or both eyes are opened(I arbitrarily assigned a 0 to an open eye and 1 to a closed eye).Depending on that output from the webcam,I want to select words from a group of 150 words and phrases(arranged in alphabetical order) to construct a sentence because what the program requires is to create a 'sign-language-like' way of communication where by what somebody wants to say can be inferred only by facial expressions(blinks),for example,communicating with somebody who doesn't talk.
To be clear,the program decides the meaning of the sentence depending on the eye closed or opened or if both eyes are open(if left eye is close,a word from the first third is selected and if the the right eye is closed,a word is selected from the second third and if all the eyes are closed,then a word is selected from the last third).And if it takes long before any webcam output is received,then the program just ends).
Andrew Newell
Andrew Newell on 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.

Sign in to comment.

Answers (3)

Matt Fig
Matt Fig on 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 Comments
John
John on 29 Jan 2011
The words are in a 3-by-50 array and they are divided in aphabetical order(first third from A-I,second third from J-R and the last third from S-Z).So, what the program basically requires me to do is to select words that would make a meaningful sentence from any third of aphabet.
Jiro Doke
Jiro Doke on 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.

Sign in to comment.


Andrew Newell
Andrew Newell on 29 Jan 2011
If your goal is to search for a given string in a cell array, you can use strcmp.

Jiro Doke
Jiro Doke on 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.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!