简体   繁体   English

将目录中的所有CSV文件导入MATLAB中的数据存储区

[英]Importing all CSV files from a directory into Datastore in MATLAB

I have 450 *.csv files in a directory and I want to collect/import all of them into one datastore for further processing. 我的目录中有450个*.csv文件,我想将它们全部收集/导入到一个 datastore以进行进一步处理。 I have used the following code for collecting all the CSV files into one datastore. 我使用以下代码将所有CSV文件收集到一个数据存储中。

       Path = 'Data/Dataset Collection/';
       Files = dir(Path);
       for k = 1 : length(Files)
          FileNames = Files(k).name;

          if (~strcmp(FileNames, '.'))
              if (~strcmp(FileNames, '..'))
                  ds = datastore([Path  FileNames], 'TreatAsMissing', 'NA');

                  if k == 3
                  ds_All = ds;
                  else
                  ds_All = [ds_All ds];
                  end
              end
          end

But, I am facing with this error: 但是,我面临着这个错误:

Array formation and parentheses-style indexing with objects of class 'matlab.io.datastore.TabularTextDatastore' is not allowed. 不允许使用类别为'matlab.io.datastore.TabularTextDatastore'的对象进行数组形成和括号式索引。 Use objects of class 'matlab.io.datastore.TabularTextDatastore' only as scalars or use a cell array. 只能将类'matlab.io.datastore.TabularTextDatastore'的对象用作标量或使用单元格数组。

I have two questions: 我有两个问题:

1- How can I use the better coding to only use one datesotre ( only ds ), NOT two ( ds and ds_All ). 1-我如何使用更好的编码来仅使用一个 datestore( only ds ),而不是两个( ds and ds_All )。

2- If my solution is well enough, how can I overcome the error? 2-如果我的解决方案足够好,如何克服该错误?

From the Matlab online help : Matlab在线帮助中

ds = datastore(location) creates a datastore from the collection of data specified by location. ds = datastore(location)根据location指定的数据集合创建数据存储。 A datastore is a repository for collections of data that are too large to fit in memory. 数据存储区是用于存储太大而无法容纳在内存中的数据的存储库。 After creating ds, you can read and process the data. 创建ds之后,您可以读取和处理数据。

So it seems you can just initialize your datastore by the folder where the files are in. Have you tried 因此,看来您可以仅通过文件所在的文件夹来初始化数据存储。

Path = 'Data/Dataset Collection/';
ds = datastore(Path);

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

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