0

I have 50 images, I want to write data into text file in matlab for each image column wise but when I run the programe it will write data only one image value.

srcFiles = dir('E:\practice \\*.jpg');
for i = 1 : length(srcFiles)
  filename = strcat('E:\practice\',srcFiles(i).name);
  I = imread(filename);
  B=bwlabel(I);
  D=regionprops(B,'MajorAxisLength','MinorAxisLength','Extent');
  j=D.MajorAxisLength;
  k=D.MinorAxisLength;
  Axialratio=j/k
  ex=[D.Extent]
  fid=fopen('mu.txt ','wt+');
  fprintf(fid,'extent  Axialratio\n');
  fprintf(fid,'%6f     %6f \n',[ex,Axialratio]);
  fclose(fid);
end 
4

1 回答 1

0

您正在fopen使用wt+选项。首先,没有这样的选择。也许你的意思是w+。文档说:

Open or create new file for reading and writing. Discard existing contents, if any.

因此,每次进入for每个图像的循环时,您都会丢弃内容。请执行下列操作:

srcFiles = dir('E:\practice \\*.jpg');
fid=fopen('mu.txt ','w+');
for i = 1 : length(srcFiles)
  filename = strcat('E:\practice\',srcFiles(i).name);
  I = imread(filename);
  B=bwlabel(I);
  D=regionprops(B,'MajorAxisLength','MinorAxisLength','Extent');
  j=D.MajorAxisLength;
  k=D.MinorAxisLength;
  Axialratio=j/k
  ex=[D.Extent]

  fprintf(fid,'extent  Axialratio\n');
  fprintf(fid,'%6f     %6f \n',ex,Axialratio); //Also don't create a matrix, you could have written it as two separate quantities as I have done now.
 end 
fclose(fid);

这应该有效。

于 2013-03-02T19:34:40.080 回答