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.
回答(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!