Prev: help
Next: piexel counting of HSV image
From: us on 22 Jul 2010 14:09 "Reza Zare" <persianfriend12(a)yahoo.com> wrote in message <i290o4$c6p$1(a)fred.mathworks.com>... > Hello All, > > I have a text file( sample.txt) containing some numbers, I wana write all the similar number into another file and delete them from original file? pls advise me on this... my code is as follow: for this case, first, fourth and fifth line are having similar number, so I have written this three numbers into another file, how can I delete them from the sample.txt. > > sample.txt > ********************** > 1880 1121-127-700-500 > 1882 1121-115-710-400 > 1891 1121-115-700-400 > 1892 1121-127-700-500 > 1893 1121-127-700-500 > ... > > ********************** > for i=1:12 > fid=fopen('sample.txt'); > c=textscan(fid,'%s %s'); > a=c{2}{1}; > a1=c{2}{i}; > tf=isequal(a,a1); > if (tf==1) > fid1=fopen('class1.txt','a+'); > fwrite(fid1, c{1}{i}); > end > end > fclose(fid1); > fclose(fid); one of the many solutions - using your exemplary file's content... fold='foo.txt'; % <- your file name fnew='foo_new.txt'; clear s t; [s,t]=textread(fold,'%d%s','delimiter','\n'); ix=ismember(t,t(1)); fp=fopen(fnew,'wt'); if fp > 0 fprintf(fp,'%d\n',s(ix)); fclose(fp); end type(fnew); %{ 1880 1892 1893 %} us |