简体   繁体   English

将多个csv文件中的数据合并到一个单元中

[英]Pooling data from multiple csv files into a cell

I have 33 csv files from different locations and I would like retrieve each file, get the content and dump it in a cell. 我有33个来自不同位置的csv文件,我想检索每个文件,获取内容并将其转储到单元格中。 This cell should contain information (all scalar values) from all the individual files. 该单元格应包含来自所有单个文件的信息(所有标量值)。 Each individual file has 3 rows and 16 columns. 每个文件都有3行和16列。 I would like to create a 99 x 16 cell (called P). 我想创建一个99 x 16的单元格(称为P)。 99 rows would be from 3 rows per each of the 33 files. 在33个文件中的每个文件中,有3行来自99行。 The 16 columns are 16 columns from each file. 16列是每个文件的16列。

So far I have created a loop to retrieve each file: 到目前为止,我已经创建了一个循环来检索每个文件:

P=cell(length(Q)*3,16); P =细胞(长度(Q)* 3,16); % Q contain the name of the files %Q包含文件名

for k=1:length(Q) 对于k = 1:length(Q)

dire_FIX = '/Data3/ledata/FHSWD/Scan_data/'; dire_FIX ='/ Data3 / ledata / FHSWD / Scan_data /';

data_path=[dire_FIX Q{k}]; data_path = [dire_FIX Q {k}];

data = spm_select('FPList', fullfile(data_path), sprintf('^%s.*\\.csv$', Q{k})); 数据= spm_select('FPList',fullfile(data_path),sprintf('^%s。* \\。csv $',Q {k})); % get each file %获取每个文件

Values = load (data) 值=负载(数据)

Here is where I got stuck. 这是我卡住的地方。 Values should be a 3x16 cell. 值应为3x16的单元格。 How do I put each Values into P without overwriting the previous Values. 如何将每个值放入P中而不覆盖以前的值。

Thank you! 谢谢!

Initialize P to an empty matrix: 将P初始化为一个空矩阵:

P =[];

Put this at the end of your for-loop: 将其放在for循环的末尾:

P(:, end+1) = Values{:, 1};
P(:, end+1) = Values{:, 2};
P(:, end+1) = Values{:, 3};

That should do it. 那应该做。

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

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