matlab读取txt文本内容修改并保存到txt

来源:互联网 发布:复杂网络的同步 编辑:程序博客网 时间:2024/05/16 13:40

原txt文本内容

bbox1.txt

D:\VStest\xiazai\code_point\CASIA-maxpy-clean\0000045\001.jpg 67 181 79 194
D:\VStest\xiazai\code_point\CASIA-maxpy-clean\0000045\002.jpg 71 186 79 195
D:\VStest\xiazai\code_point\CASIA-maxpy-clean\0000045\003.jpg 65 178 78 191
D:\VStest\xiazai\code_point\CASIA-maxpy-clean\0000045\004.jpg
D:\VStest\xiazai\code_point\CASIA-maxpy-clean\0000045\005.jpg
D:\VStest\xiazai\code_point\CASIA-maxpy-clean\0000045\006.jpg 70 182 79 191

......

修改后txt文本内容

NewData.txt

0000045\001.jpg 67 181 79 194
0000045\002.jpg 71 186 79 195
0000045\003.jpg 65 178 78 191
0000045\004.jpg
0000045\005.jpg
0000045\006.jpg 70 182 79 191
0000045\007.jpg
0000045\008.jpg 66 180 77 191
0000045\009.jpg 68 174 82 188
0000045\011.jpg
0000045\012.jpg 59 174 81 196
0000045\013.jpg 63 173 76 186
0000045\014.jpg
0000045\015.jpg 63 178 76 191

......


fin=fopen('D:\VStest\xiazai\code_point\bbox1.txt','r');

fout=fopen('D:\VStest\xiazai\code_point\NewData.txt','w');
while ~feof(fin)    
    tline = fgets(fin);
    if( ~ischar(tline) )
        break;
    end
    y=tline(47:end);      
    fprintf(fout,'%s',y);
end
fclose(fin);
fclose(fout);
0 0