Associate filename to datastore read data

3 ビュー (過去 30 日間)
mlwnr
mlwnr 2019 年 1 月 7 日
回答済み: James Hong 2020 年 4 月 24 日
Hello,
I am reading over 2000 .xls files into a datastore:
Here is the code I wrote until now:
location = 'C:\test';
ssds = spreadsheetDatastore(location,'NumHeaderLines',1);
ssds.ReadSize = 3000;
ssds.SelectedVariableNames = 'MyName';
whatsNeeded=readall(ssds);
I know have 3000 datapoints (from over 700000) of the .xls column 'MyName' in the variable whatsNeeded.
For example:
whatsNeeded(1) = 'Number1'
whatsNeeded(2) = 'Number2'
...
whatsNeeded(172) = 'Number1'
...
whatsNeede(1583) = 'Number1'
...
whatsNeeded(3000) = 'Number1'
I now need the info, from which original file/from which filename the variables (1), (172), (1583) & (3000) came.
Is there a way to associate these information?
Thank you.

回答 (1 件)

James Hong
James Hong 2020 年 4 月 24 日
As of R2020a, there is no direct way to do this, but a workaround is to append the data with a column that identifies the filename:
ds = ...
ds = transform(ds, @addFilenameToData, 'IncludeInfo', true);
tt = tall(ds)
where 'addFilenameToData' is defined:
function [data, info] = addFilenameToData(data, info)
[~, filename, ext] = fileparts(info.Filename);
data.Filename(:, 1) = string([filename ext]);
end

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by