唉,叫你把fopen和fclose放到循环外面,不是fprintf
汗啊!
fid = fopen('exp.txt','w');
for i=1:length(D)
for j=1
A=imread(['D',num2str(D(i)),'_',num2str(j),'.tif']);
if (j==1)
figure(1),BW = roipoly(A);
end
IM=double(A).*double(BW);
level=graythresh(IM)
BW = im2bw(IM,level);
if (j==1)
figure(2),imagesc(BW),
surf(i)=bwarea(BW)/(640*480) %4.8095e+004 15.61%
m=[i,surf(i)];
end
fprintf(fid,'%6.2f %12.8f\n',m);
end
end
fclose(fid);
把fopen和fclose放到循环外面,现在这个样子相当于每次都新建一个文件