![](/img/trans.png)
[英]Any function in matlab to write the output of matlab code to excel file each time the code gets executed without over writing the data
[英]writing output data into excel file in matlab
我有50張圖像,我想針對每一圖像列將數據寫入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
您正在使用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);
這應該工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.