필터 지우기
필터 지우기

Why readtable is not reading all my rows, it has a limit?

조회 수: 36 (최근 30일)
Estefany Patricia Vizuete Chacón
I'm trying to read a table with the code
datos = readtable('tmy.xlsx');
datos(4:8763,1:15)
But when I see the read data in the workspace, a matrix of 8708x27 table appears when the original file is 8763x27. I tried to put the size but it comes out:
Error using ()
Row index exceeds table dimensions.
Error in tmy_datos_tratados (line 3)
datos(4:8763,1:15)
It should be noted that in the Excel file everything is in number format and there are no empty cells.
Please help me, thank you so much.

답변 (1개)

Steven Lord
Steven Lord 2024년 5월 13일
I believe the presence of data in P56 makes MATLAB consider rows 1 through 55 as headers. Note that detectImportOptions considers your data to start in cell A56.
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1693421/tmy.xlsx';
IO = detectImportOptions(filename)
IO =
SpreadsheetImportOptions with properties: Sheet Properties: Sheet: '' Replacement Properties: MissingRule: 'fill' ImportErrorRule: 'fill' Variable Import Properties: Set types by name using setvartype VariableNames: {'Var1', 'Var2', 'Var3' ... and 13 more} VariableTypes: {'double', 'double', 'double' ... and 13 more} SelectedVariableNames: {'Var1', 'Var2', 'Var3' ... and 13 more} VariableOptions: [1-by-16 matlab.io.VariableImportOptions] Access VariableOptions sub-properties using setvaropts/getvaropts VariableNamingRule: 'modify' Range Properties: DataRange: 'A56' (Start Cell) VariableNamesRange: '' RowNamesRange: '' VariableUnitsRange: '' VariableDescriptionsRange: '' To display a preview of the table, use preview
If I update the import options to indicate the data starts at A4 (and the variable names are in the third row)
IO.DataRange = 'A4';
IO.VariableNamesRange = 'A3';
T = readtable(filename, IO);
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
head(T)
Year Month Day Hour Minute Temperature DHI DNI WindSpeed WindDirection Pressure GHI DewPoint Var14 Var15 Var16 ____ _____ ___ ____ ______ ___________ ___ ___ _________ _____________ ________ ___ ________ ______ __________ _____ 2022 1 1 0 30 11.4 0 0 1.3 303 727 0 11.4 11.4 {0x0 char} NaT 2022 1 1 1 30 11.101 0 0 1.1 299 728 0 11101 11.101 {0x0 char} NaT 2022 1 1 2 30 10.701 0 0 0.9 292 728 0 10701 10.701 {0x0 char} NaT 2022 1 1 3 30 10.3 0 0 0.9 283 728 0 10.3 10.3 {0x0 char} NaT 2022 1 1 4 30 10 0 0 0.8 277 728 0 10 10 {0x0 char} NaT 2022 1 1 5 30 9.8 0 0 0.701 273 727 0 9.8 9.8 {0x0 char} NaT 2022 1 1 6 30 9.601 0 0 0.601 272 727 0 9601 9.601 {0x0 char} NaT 2022 1 1 7 30 9.5 0 0 0.5 274 727 0 9.5 9.5 {0x0 char} NaT
size(T)
ans = 1x2
8760 16
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by