How to display each individual word of a string
조회 수: 6 (최근 30일)
이전 댓글 표시
hi all,
How can I display each word of a string individual? I wrote a loop, but it does not work.
댓글 수: 1
답변 (3개)
Mischa Kim
2014년 2월 5일
Use
my_str = strsplit('This is a test');
for ii = 1:length(my_str)
display(my_str{ii});
end
댓글 수: 0
Azzi Abdelmalek
2014년 2월 5일
str='How to display each individual word of a string'
out=regexp(str,' ','split')
vikash kumar
2017년 12월 26일
편집: vikash kumar
2017년 12월 26일
word_loc = find(sentence==' ' | sentence =='.');
count = size(word_loc,2);
words = cell(count,1);
prev=1;
for i=1:count
words{i}= sentence(prev:word_loc(i)-1);
prev = word_loc(i)+1;
end
댓글 수: 1
Walter Roberson
2017년 12월 26일
The difficulty with this is that it splits numbers like 3.14 and it splits abbreviations like "e.g."
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!