How to ignore punctuation in a user string while scanning for words (textscan())?
조회 수: 3(최근 30일)
표시 이전 댓글
It works perfectly now. thanks to oleg and lucas for ur help! if ur interested, here's how it looks like in the end:
function pushbutton1_Callback(hObject, eventdata, handles)
words = get(handles.editbox, 'string'); %scans user input string from editbox
wavdirectory = 'C:\Program Files\MATLAB\R2010b\Recordings\';
wordsstring = regexp(words, '\w+', 'match') ; %reads string only, ignores punctuation
[j, k] = size(wordsstring); %stores number of words in user input string
for m = 1:k
thisfid = [wavdirectory wordsstring{m} '.wav'];
try
[y, fs] = wavread(thisfid);
sound(y, fs);
catch
fprintf(1,'Failed to process file wave "%s" because: ', thisfid);
lasterror
end
end
댓글 수: 1
Oleg Komarov
2011년 9월 1일
How do you get the user-input? http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
채택된 답변
Lucas García
2011년 9월 1일
This removes the specified punctuation in your word:
regexprep(word, '[-!,.?]', '')
추가 답변(2개)
Oleg Komarov
2011년 9월 1일
If you want more details provide some example inputs and required output.
From Lucas' example:
word = {'this.-is..!a,test', 'it!!.works???-'};
C = regexp(word, '\w+', 'match')
Walter Roberson
2011년 9월 1일
Ah, the poster broke this out in to a separate question, which I did not see before I answered in the original thread. My answer there was:
Before the textscan:
words = lower(words);
words(~ismember(words, ['a':'z' ' '])) = ' ';
then go ahead with the textscan
On second look, that could be shortened to
words = lower(words);
words(~ismember(words, 'a':'z')) = ' ';
댓글 수: 0
참고 항목
범주
Find more on Text Data Preparation 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!