Associate filename to datastore read data
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
James Hong
am 24 Apr. 2020
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Datastore finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!