Exact string matching

10 Ansichten (letzte 30 Tage)
Gurusaran
Gurusaran am 15 Okt. 2011
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 Kommentare
Gurusaran
Gurusaran am 16 Okt. 2011
And brother, this is not my homework nor you have to do it for me, I'm just curious and need a kick start.
Jan
Jan am 16 Okt. 2011
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 16 Okt. 2011
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.
Biggest trick: you will need to set two optional modes for regex, as shown here

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by