Exact string matching
显示 更早的评论
How do I write a code, that finds repeated words from an input file and prints those with its position, i.e. (where it was found)
4 个评论
Jan
2011-10-15
Please post, what you have done already and ask for a specific question. This forum is not a programming robot and we will not solve your homework.
Gurusaran
2011-10-16
Gurusaran
2011-10-16
Jan
2011-10-16
Ok, no homework. Even if you are new at Matlab, I assume you can implement the reading of a text file by your own. Then it would be useful if you implement as much as you can and ask a specific question. For such general questions there is a discrepancy between the effort needed to create a meaningful answer, and the effort shown by the author.
回答(1 个)
Walter Roberson
2011-10-16
0 个投票
Read the file in to a string, newlines and all. Use regex() to extract the "words" and corresponding locations (for whatever you define a "word" to be.) Use the three-output form of unique() to get the unique words and the corresponding indices into the original list of words. Index the location list by that index list to get the word positions.
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!