如何matlab 读取同一个文件中的多个txt 文档

发布时间:2013-06-10 09:45:31

function data = readall_txt(path)

% READALL_TXT 读取所有文件

% DATA = READALL_TXT(PATH)读取路径PATH下的所有txt文件中的数据赋给data

% txt文件中含有一个数据项

% 输出cell格式以免各txt中数据长度不同

%

% 原始版本:V1.0 作者:李鹏 时间:2009.04.04

A = dir(fullfile('E:\shuju','*.txt'));

% 读取后A的格式为

% name -- filename

% date -- modification date

% bytes -- number of bytes allocated to the file

% isdir -- 1 if name is a directory and 0 if not

A = struct2cell(A);

num = size(A);

for k =0:num(2)-1

x(k+1) = A(5*k+1);% 找出name序列

end

for k = 1:num(2)

newpath = strcat('E:\shuju','\',x(k));

data{k} = load(char(newpath));

end

% [EOF] readall_txt.m

%以上程序保存为.m文件后,在matlab命令窗口输入 data=readall_txt('E:\shuju')

如何matlab 读取同一个文件中的多个txt 文档

相关推荐