Reading in xls files from folder- saving data with identifier from filename
1 次查看(过去 30 天)
显示 更早的评论
Hi, I have a folder full of xls files, named data_00001 through data_10000. Each file has a dozen or so identically named tabs full of RV's. I am interested in reading all files and tabs and creating histograms of the RV's.
Is there a way to read in the last 5 digits of the file names and attached them to each tab name (which I saved as a variable) ? Then each variable is a n*1 cell array, where each cell contains the raw RV data?
I used regexp to extract the number as a string and converted it to a double, and I used a for loop to save variable X {1,k} via importdata. How can I incorporate the saved double into this variable?
0 个评论
回答(1 个)
Cedric
2013-11-1
编辑:Cedric
2013-11-5
You can build a solution based on the following (not tested).
D = dir( 'Z:\MyFiles\FileName\d*.xls' ) ;
tabs = {'X', 'Y', 'Z'} ;
nFiles = length( D ) ;
nTabs = length( tabs ) ;
data = cell( nFiles, nTabs ) ;
for fId = 1 : nFiles
for tId = 1 : nTabs
idStr = D(fId).name(6:10) ;
data{fId,tId} = xlsread( D(fId).name, tabs{tId} ) ;
end
end
Let me know if your setup is different (in particular for tab names), and I can adapt the answer.
2 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!