필터 지우기
필터 지우기

Reading in xls files from folder- saving data with identifier from filename

조회 수: 1 (최근 30일)
Mike
Mike 2013년 11월 1일
편집: Cedric 2013년 11월 5일
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?

답변 (1개)

Cedric
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
Mike
Mike 2013년 11월 3일
Cedric- thanks for your post. I apologize for the confusion in my question, the tabs are not identically named in the sense of Results 1- n, but rather X,Y,Z... where each file has the same tabs.
I had a question - in D, can I replace '*.xls' with the path of the folder?ie... 'Z:\MyFiles\FileName\d*).xls' ?
Also, the For fID loop is as below? for fId = 1 : nFiles
Cedric
Cedric 2013년 11월 5일
편집: Cedric 2013년 11월 5일
Hi Mike, you are right, the nFiles was truncated in one of my edits. See my updated answer and let me know if anything is unclear or doesn't apply to your case.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by