matlab批量讀寫與處理大量一樣的Text

%批量求均值
clc
clear
file=dir('C:\Users\tt\Desktop\density\*.log');%文件格式
                 
 for h=1:length(file)%計算文件數目
     fid(h)=fopen(['C:\Users\tt\Desktop\density\',file(h).name],'r');%循環讀取文件
for i=1:12
    for j=1:7                        %文件行列數,自行調整
    for j=1:7                                                 
        date{i,j}=fscanf(fid(h),'%s',[1,1]);%cell型數組存儲數據
    end
end
fclose(fid(h));
for i=1:12                           %文件行數
    date1{i,j}=str2double(date{i,j});%把字符cell轉化成double型
    end
end
    for i=1:10
        n=i+2;%從第三行計算
        densi(i)=date1{n,2};%提取第二列
        temp(i)=date1{n,3};%提取第三列
    end
    den(h)=mean(densi(:));
    t(h)=mean(temp(:));
end
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章