同时读取两个文件,每个文件都有标题行以跳过

时间:2015-07-13 02:44:06

标签: matlab file-io

我有两个.txt文件,每个文件都有13行标题信息需要跳过。

我将它们合并到一个文件中,但这不起作用,因为它没有跳过第二批标题行。

    DELIMITER = '\t';
    %HEADERLINES = 13;

    % Import the file

    system('copy A.txt+B.txt C.txt')

    newData1 = importdata('C.txt', DELIMITER, HEADERLINES);

    % Create new variables in the base workspace from those fields.
    vars = fieldnames(newData1);
    for i = 1:length(vars)
        assignin('base', vars{i}, newData1.(vars{i}));
    end

1 个答案:

答案 0 :(得分:1)

尝试:

% Read in the two files separately into matrices (skipping the header)
dat_a = dlmread('A.txt', DELIMITER, HEADERLINES, 0);
dat_b = dlmread('B.txt', DELIMITER, HEADERLINES, 0);

% Combine and write to the new file
dlmwrite('C.txt', [dat_a; dat_b], DELIMITER);

查看文档(dlmreaddlmwrite)以获取更多信息。