Selecting words in MATLAB
조회 수: 2 (최근 30일)
이전 댓글 표시
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년 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
>>
댓글 수: 2
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
2011년 1월 29일
If your goal is to search for a given string in a cell array, you can use strcmp.
댓글 수: 0
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 String Parsing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!