在fopen里用wt要将fopen、fclose放在循环外,每执行一次fopen\fclose可以刷新输出的eye.txt。
mainpath = 'D:\Album2';
dirname = fullfile( mainpath, '*.jpg' );
subdir = dir( dirname );
fid = fopen('D:eye.txt', 'wt');
for i = 1 : length( subdir )
imagepath = fullfile( mainpath, subdir( i ).name);
x=load(imagepath);
xeye=[x(11,:),x(12,:)];
%txt输出
fprintf(fid, '%s %5.4f %5.4f %5.4f %5.4f\n', imagepath, xeye);
end
在fopen里用at要将fopen、fclose放在循环内,每次执行程序继续上次的eye.txt,继续写。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
clc;mainpath = 'D:\Album2';
dirname = fullfile( mainpath, '*.jpg' );
subdir = dir( dirname );
fid = fopen('D:eye.txt', 'wt');
for i = 1 : length( subdir )
imagepath = fullfile( mainpath, subdir( i ).name);
x=load(imagepath);
xeye=[x(11,:),x(12,:)];
%txt输出
fprintf(fid, '%s %5.4f %5.4f %5.4f %5.4f\n', imagepath, xeye);
end
fclose(fid);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
clc;
mainpath = 'D:\Album2';
dirname = fullfile( mainpath, '*.jpg' );
subdir = dir( dirname );
for i = 1 : length( subdir )
imagepath = fullfile( mainpath, subdir( i ).name);
x=load(imagepath);
xeye=[x(11,:),x(12,:)];
%txt输出
fid = fopen('D:eye.txt', 'at');
fprintf(fid, '%s %5.4f %5.4f %5.4f %5.4f\n', imagepath, xeye);
fclose(fid);
end