How to compare similar lines of two text files
이전 댓글 표시
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
Walter Roberson
2016년 6월 11일
What do you want to have happen when a line is considered to match or to not match?
Is there a need to watch out for deletions, where a line might simply not be present, so you might end up (for example) matching line 8 of one with line 7 of the other?
Muhammad Usman Saleem
2016년 6월 11일
Please provide explaination on Comparision meaning?
Fateme Jalali
2016년 6월 12일
Muhammad Usman Saleem
2016년 6월 12일
see Stalin Samuel answer
Walter Roberson
2016년 6월 12일
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.
답변 (1개)
Stalin Samuel
2016년 6월 11일
0 개 추천
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!