Import multiple excel sheets with multiple columns each into variables
조회 수: 7 (최근 30일)
이전 댓글 표시
Hey, I would like to import data from excel with multiple sheets. Every sheets has 2 columns and I would like to create a variable of every column in every sheet. How can I do this in Matlab?
댓글 수: 0
채택된 답변
Rishabh Rathore
2018년 5월 31일
You can use xlsread(xls_file,sheet_no) to read from particular sheet, refer documentation. It will return data in matrix form. Once you have that, use array indexing to extract individual columns ,Matrix(:,col) gives column 'col' of 'Matrix'.
Using xlsread, loop through all the sheets to get data from individual sheets.
댓글 수: 2
Stephen23
2018년 5월 31일
편집: Stephen23
2018년 5월 31일
"how can I create this loop and give every variable a name combined with the name of the sheet?"
Don't do that, unless you want to force yourself into writing slow, complex, buggy code that is hard to debug. Read this to know why dynamically accessing variable names is a bad way to write code:
Use indexing. Indexing is simple, neat, and very efficient. Indexing is what you should use. Store the sheet names and sheet data in cell arrays, and access them trivially using indexing.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!