经常读取多个文件,但是经常忘记把代码放在电脑具体位置,直接搬到网上。
目录
for循环读取文件
% ReadASCIIForLoop
% 用 for 循环读取 ascii 文件,后缀为'.txt'
clear;close all;clc;
filePath = 'D:\FO\KKK\sample\'; % 读取文件的地址
fileHeadName = 'fluent-'; % 读取文件的头标题
startnum = 20020; %文件开始的编号
endnum = 20030; %文件结束的编号
step = 1; %文件编号的步进
%找到文件的变量名称
CFD_raw = importdata(strcat(filePath,fileHeadName, int2str(startnum), '.txt'));
variables_names = arrayfun(@(str) strrep(str,' ',''),CFD_raw.colheaders);
variables_names = arrayfun(@(str) strrep(str,'-','_'),variables_names);
CFD_raw = array2table(CFD_raw.data, 'VariableNames', variables_names);
[row,col] = size(CFD_raw);
varibleName = variables_names(2:col);
clear CFD_raw variables_names
data =