简体   繁体   English

如何在Matlab中读取多个日志文件

[英]how to read multiple log files in Matlab

I would like to open multiple log files, and concatenate them so that they make one big log file, from which I can then extract the information I need. 我想打开多个日志文件,并将它们连接起来,以便它们构成一个大日志文件,然后从中提取所需的信息。

I would like matlab to open as many files, as there are in my folder, based on the name including a certain string. 我希望matlab根据名称(包括某个字符串)打开尽可能多的文件,与我的文件夹中的文件一样。

here is my code so far: 到目前为止,这是我的代码:

pilotfiles = dir (['*PILOT*.log'])

for fil=1:length(pilotfiles)
    files{fil}=pilotfiles(fil).name;
end;
   files=char(files);

for fil = 1:length (files (:,1));
    clear logs;
    file_name = files (fil,:);
    noofColumns = 45;
    cs = repmat('%s', 1, noofColumns);
    fileID = fopen(deblank(file_name));
    logs = textscan(fileID,cs); 
    biglog = horzcat (logs {:}); 
    fclose (fileID);    
end

Of course, I would not be asking this question if the code worked. 当然,如果代码有效,我不会问这个问题。

file_name correctly returns names of all my files, 'logs' seems to read the contents of each of the files, but then my 'biglog' only contains the contents of the last log file . file_name正确返回了我所有文件的名称,“ logs”似乎读取了每个文件的内容,但是我的“ biglog”仅包含了最后一个日志文件的内容。

Anybody has any ideas where am I making the mistake? 有人对我在哪里犯错误有任何想法吗?

NOTE: I am working on a MAC, this code is based on a code, which has worked on a PC 注意:我正在使用MAC,此代码基于在PC上工作的代码

pilotfiles=dir('*PILOT*.log');
pilotfiles=pilotfiles(3:end);
N=numel(pilotfiles);
logs=cell(1,N);
cs=repmat('%s',1,45);
for i=1:N
    fid=fopen(fullfile(pilotfiles(i).folder,pilotfiles(i).name));
    logs{i}=textscan(fid,cs);
    logs{i}=[logs{i}{:}];
    fclose(fid);
end
biglog=[logs{:}];

Cheers. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM