removing duplicate data
이전 댓글 표시
[EDIT: 20110513 00:34 CDT - reformat - WDR]
I have a text file containing some data and there are some duplicates
line1 : 123 456 789
line2 : 123 456 789
line3 : 234 567 890
line4 : 123 456 789
line5 : 456 789 012
how can I remove the repeated data and save back to my txt file?
답변 (1개)
Matt Fig
2011년 3월 25일
0 개 추천
Load the data, call the UNIQUE function with the rows option, then save the result.
댓글 수: 9
Hoa
2011년 3월 25일
Matt Fig
2011년 3월 25일
Then you need to be more specific. Given the data:
123 456 789
123 456 789
234 567 890
123 456 789
456 789 012
What do you expect the output to be? Do you want the output to be:
123
456
789
234
567
890
012
or, did you want the output to be:
123 456 789
234 567 890
456 789 012
Hoa
2011년 3월 25일
Jan
2011년 3월 25일
Then UNIQUE(Data, 'rows') should work.
Matt Fig
2011년 3월 25일
fid = fopen('mydata.txt','r');
T = textscan(fid,'%f%f%f','collectoutput',1);T = T{1};
U = unique(T);
fclose(fid);
fid = fopen('mydata.txt','w');
fprintf(fid,'%g\r',U.');
fclose(fid);
Hoa
2011년 3월 26일
Walter Roberson
2011년 3월 26일
Please show your current code.
Hoa
2011년 3월 27일
Walter Roberson
2011년 3월 27일
Change the line
fprintf(fid,'%g\r',U.');
to
fprintf(fid,'%g\n',U.');
카테고리
도움말 센터 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!