How to extract certain rows and columns with the readtable option for Excel files.
조회 수: 184 (최근 30일)
이전 댓글 표시
Suppose we have an Excel file Data.xlsx. The file have certain descriptive text in the initial rows and then there is tabular data on several sheets. I would like to extract column 1 and column 3 but the useful row number starts from say, 30 and ends at 10000.
Table1=readtable('Data.xlsx', 'Sheet', 'Signal', 'Range', 'A:C');
Is there a better way to read such an Excel file? There is a lot of text in the initial rows of the Excel file. This is default way the instrument exports the data. How can we only read column A and column C whose useful rows start from 30 and end at 10000?
Thanks.
댓글 수: 0
답변 (1개)
Sindar
2020년 1월 24일
편집: Sindar
2020년 1월 24일
(edited)
Using the import tool, then generating code and clearing unnecessary details, this appears to be the way:
opts = spreadsheetImportOptions("NumVariables", 3);
% Specify sheet and range
opts.Sheet = "Signal";
opts.DataRange = "A30:C10000";
% Specify column names and types
opts.VariableNames = ["A", "Var2", "C"];
opts.SelectedVariableNames = ["A", "C"];
% Import the data
Table1 = readtable("Data.xlsx", opts);
댓글 수: 8
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!