How do I create datastore class interactively?

1 回表示 (過去 30 日間)
Himanshi Rani
Himanshi Rani 2017 年 5 月 8 日
回答済み: Edric Ellis 2017 年 5 月 9 日
I have a folder of spreadsheet files containing three subfolders. I am using datastore to read the data from the spreadsheets.
I need to get the data from each of the subfolders individually and store them as ds1,ds2,ds3 for subfolder1,2 and 3 respectively.
I am doing the following:
for k = 1:3
ds = datastore('subfolder%d.xls',k)
end
I get the following errors:
Error in datastore:
Expected a string for the parameter name, instead the input type was 'double'.
Error in datastore>parseFileBasedNVPairs
parse(inpP, varargin{:});
Error in datastore
fileBasedNV = parseFileBasedNVPairs(varargin{:});
I am able to understand the origin of first error, but then I cannot find any way to resolve it.

採用された回答

Steven Lord
Steven Lord 2017 年 5 月 8 日
You're missing an sprintf call. You should probably also store your datastore objects in a cell array (or perhaps a regular array of datastore objects; I'm not certain off the top of my head if that's allowed.)
ds{k} = datastore(sprintf('subfolder%d.xls',k))

その他の回答 (1 件)

Edric Ellis
Edric Ellis 2017 年 5 月 9 日
Further to @Steven's suggestion, you might instead wish to create a single datastore referring to all the files. See the documentation for more, but basically you could do:
ds = datastore('subfolder*.xls');
or perhaps the following which explicitly picks only files 1:3.
fileNames = strcat('subfolder', strsplit(num2str(1:3)), '.xls');
ds = datastore(fileNames);

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by