1.文件写入、读取
%% 写入
fin=fopen('.\df_txt\Data.txt','a+');
% fin=fopen('.\df_txt\Data.txt','a+');
fprintf(fin,'\r\n ------------------------------ \r\n');
fprintf(fin,'%d\t%d\t%d\t%d\t%d\t%d\r\n',fix(clock));
fprintf(fin,'%d %d %d %d \r\n',Boxin);
% fprintf(fin,'boxpara.s \r\n');
% fprintf(fin,'featkindpara: \r\n');
fclose(fin);
%%
dlmwrite('sample_result.txt',groundtruth_matrix,'precision','%10.0f');
%%
a =[17 24 1 8 15;23 5 7 14 16 ;4 6 13 20 22 ;10 12 19 21 3 ;11 18 25 2 9 ];
save afile.txt -ascii a
afile.txt打开之后,是这样的:
1.7000000e+001 2.4000000e+001 1.0000000e+000 8.0000000e+000 1.5000000e+001
2.3000000e+001 5.0000000e+000 7.0000000e+000 1.4000000e+001 1.6000000e+001
4.0000000e+000 6.0000000e+000 1.3000000e+001 2.0000000e+001 2.2000000e+001
1.0000000e+001 1.2000000e+001 1.9000000e+001 2.1000000e+001 3.0000000e+000
1.1000000e+001 1.8000000e+001 2.5000000e+001 2.0000000e+000 9.0000000e+000
%% 读取
fout=fopen('.\df_txt\girl_gt.txt','r');
result=fscanf(fout,'%d,%d,%d,%d');
disp(result(1));disp(result(2));disp(result(3));disp(result(4));
fclose(fout);
%%
1. A=importdata('filename.txt') 则A就是n*m的矩阵了;
%%
2. 程序开头删除已有文件
fid=fopen('.\df_txt\Data.txt','w+');fclose(fid);
fid=fopen('.\df_txt\Score.txt','w+');fclose(fid);
3. 删除一个目录下所有的文件夹
1
2
3
|