Filter löschen
Filter löschen

How to compare similar lines of two text files

4 Ansichten (letzte 30 Tage)
Fateme Jalali
Fateme Jalali am 11 Jun. 2016
Kommentiert: Walter Roberson am 12 Jun. 2016
hello,I have two text files including 100 lines.I want to compare same lines in two texts. for example line 1 from text 1 with line 1 in text 2 and line 2 in text 1 with line 2 in text 2 and ... I wrote this code but it compares all lines in text 1 with all lines in text 2.can any one help me to write correct codes?thanks.
fidi1 = fopen('part11.txt');
tt1 = textscan(fidi1,'%s', 'delimiter', '\n');
fclose(fidi1);
fidi2 = fopen('part22.txt');
tt2 = textscan(fidi2,'%s', 'delimiter', '\n');
fclose(fidi2);
tt1s = char(tt1{:});
tt2s = char(tt2{:});
[C,ia,ib] = intersect(tt1s,tt2s,'rows')%Find set intersection of two vectors.
common_parts = size(C,1);
  5 Kommentare
Muhammad Usman Saleem
Muhammad Usman Saleem am 12 Jun. 2016
see Stalin Samuel answer
Walter Roberson
Walter Roberson am 12 Jun. 2016
Fateme Jalali you did not answer my questions about what you want to do if they match or if they do not match, and about whether you need to worry about missing lines.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stalin Samuel
Stalin Samuel am 11 Jun. 2016

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by