简体   繁体   English

在文件中导入多个CSV

[英]Import multiple CSV in a file

I have tried to import several csv files into one file. 我试图将多个csv文件导入到一个文件中。 However, the new file overwrites the "original" ones. 但是,新文件将覆盖“原始”文件。 Only the last processed one among them was imported. 其中只有最后处理的一个被导入。 Something may be wrong about the loop, but I don't know where to change. 循环可能有问题,但是我不知道该在哪里更改。

This is what I have: 这就是我所拥有的:

p=dir('C:\foldername\*.csv');
for i=1:length(p)
     [num, text, all]= xlsread(['C:\foldername\', p(i).name]);
end

You are overriding the variables in the loop. 您正在覆盖循环中的变量。 Try to collect everything in cell array: 尝试收集单元格数组中的所有内容:

num = {};
text = {};
all = {};
p=dir('C:\foldername\*.csv');
for i=1:length(p)
    [num{end+1}, text{end+1}, all{end+1}]= xlsread(['C:\foldername\', p(i).name]);
end

You cannot read all the things into the same variables, but you can put them in different dimensions. 您不能将所有内容都读入相同的变量,但是可以将它们放到不同的维度。

p=dir('C:\foldername\*.csv');
num = cell(size(p));
text = cell(size(p));
all = cell(size(p));
for i=1:length(p)
    [num{i}, text{i}, all{i}]= xlsread(['C:\foldername\', p(i).name]);
end

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

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