2013-03-02 73 views
0

我有50個圖像,我想寫入數據到matlab中的每個圖像列明智的文本文件,但是當我運行程序時它將只寫入數據只有一個圖像值。將輸出數據寫入excel文件中的matlab

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 

回答

0

您與wt+選項做fopen。首先,沒有這樣的選擇。也許你的意思是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); 

這應該起作用。