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

Importing all CSV files from a directory into Datastore in MATLAB

我在一个目录中有 450 个 *.csv 文件,我想 collect/import 将它们全部放入 一个 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

但是,我遇到了这个错误:

Array formation and parentheses-style indexing with objects of class 'matlab.io.datastore.TabularTextDatastore' is not allowed. Use objects of class 'matlab.io.datastore.TabularTextDatastore' only as scalars or use a cell array.

我有两个问题:

1- 我怎样才能使用更好的编码来只使用 one datesotre (only ds), NOT two ( ds and ds_All).

2-如果我的解决方案足够好,我该如何克服错误?

来自Matlab online help

ds = datastore(location) creates a datastore from the collection of data specified by 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.

看来你可以通过文件所在的文件夹来初始化你的数据存储。你试过了吗

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