在fopen裡用wt要将fopen、fclose放在循環外,每執行一次fopen\fclose可以重新整理輸出的eye.txt。
在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