if(output_flag == 0)%not open already
fid=fopen('myfile.txt','w');
for i=1:rows
fprintf(fid,'%f\t%s\t%d\n',persons(i).average,persons(i).name,persons(i).age);
end
output_flag=1
else
for i=1:rows
fprintf(fid,'%f\t%s\t%d\n',persons(i).average,persons(i).name,persons(i).age);
end
end
%remember to close
if fid == -1
disp('已经关闭');
else
fclose(fid);
fid=-1;
end