error while importing excel file
조회 수: 7 (최근 30일)
이전 댓글 표시
I am trying to import an excel file into matlab environment; however, excel file contains two sheets. I want to import only one sheet whichever user imports.
[filename,pathname,~]=uigetfile('.xlsx'); %select the excel file
sheets = sheetnames(filename);
[~, ~, raw] = xlsread([pathname filename],sheets);
Error using xlsread
Sheet argument must be a string scalar, a character vector, or an integer.
Error in importfile (line 4)
[~, ~, raw] = xlsread([pathname filename],sheets);
댓글 수: 0
채택된 답변
Fangjun Jiang
2022년 12월 7일
Run the code line by line, check the value of some variables and you will find the problem easily.
[~, ~, raw] = xlsread([pathname filename],sheets);
should use fullfile(pathname,filename) to compose the full file name
sheets is a string array. You will probably need to use sheets(1)
댓글 수: 3
Fangjun Jiang
2022년 12월 7일
- Specify the sheet by number or name directly, e.g. xlsread(file, 2), xlsread(file,'sheet2')
- get the sheet names by using sheets=sheetnames(), and then compare "sheets" with the known name to find the index. This would be the most generic and robust approach.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!