フィルターのクリア

Adding filenames to compiled data

1 回表示 (過去 30 日間)
Jen
Jen 2019 年 3 月 4 日
回答済み: Nimit Dhulekar 2019 年 3 月 4 日
I have compiled data of about 200 excel sheets and need to add the file's name before each of the data sets. How can I do this easily? My code so far is:
clear all
close all
ds = spreadsheetDatastore('C:\Users\Control', 'IncludeSubfolders', true);
idx = [];
for i=1:length(ds.Files)
if strfind(ds.Files{i},'Inflections')
idx=[idx;i];
end
end
ds.Files = ds.Files(idx);
data=ds.readall();
writetable(data, 'masterexcelfile_DR.xlsx');

採用された回答

Nimit Dhulekar
Nimit Dhulekar 2019 年 3 月 4 日
I am not completely certain about the phrasing in your question: "add the file's name before each of the data sets". This is a potential way of getting filenames from the read of the datastore. Replace your existing call to readall with this loop. Every row of the table contains the name of the file in the first variable. The file name is repeated for all rows read from one file.
allData = [];
while hasdata(ssds)
[data, info] = read(ssds);
data.Filename(:) = string(info.Filename);
allData = [allData; data];
end
data = allData;
% move the last variable to the first variable in the table
data = movevars(data, "Filename", "Before", 1);

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by