Selecting words in MATLAB

조회 수: 2 (최근 30일)
John
John 2011년 1월 29일
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
John
John 2011년 1월 30일
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 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
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
>>
  댓글 수: 2
John
John 2011년 1월 29일
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 2011년 2월 1일
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
Andrew Newell 2011년 1월 29일
If your goal is to search for a given string in a cell array, you can use strcmp.

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

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by