Readtable from i-th row to last row

188 ビュー (過去 30 日間)
Clemens Gersch
Clemens Gersch 2019 年 9 月 2 日
編集済み: Jeremy Hughes 2022 年 7 月 7 日
Hi,
I am looking for a solution to read an Excel table via readtable from a specific row on down to the last row. I know in which row to start, but I don't know in before which row exactly is the last row.
The only idea I had by now was doing something like
data = readtable(workbookFile, 'sheet', sheetName, 'ReadVariableNames', true, 'FileType', 'spreadsheet', 'UseExcel', false, 'Range', '7:50000');
where 7 ist the row to start the import and 50000 is a valua that high, it would never be reached. The next step would be to delete all the empty rows, that were created (I'm still figuring out how to do it but thats not a part of my question).
That doesn't seem to be very efficient to me. Does anybody have a better solution?

採用された回答

Jeremy Hughes
Jeremy Hughes 2019 年 9 月 3 日
編集済み: Jeremy Hughes 2022 年 7 月 7 日
Try this
opts = detectImportOptions(filename,'NumHeaderLines',6)
T = readtable(filename,opts)
  1 件のコメント
Clemens Gersch
Clemens Gersch 2019 年 9 月 4 日
That's it. Thank you very very much.

サインインしてコメントする。

その他の回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 9 月 2 日
編集済み: KALYAN ACHARJYA 2019 年 9 月 2 日
Readtable from i-th row to last row?
load table, then
or
data=readtable(filename);
i=??? % define
data_read=data(i:end,:)
  1 件のコメント
Clemens Gersch
Clemens Gersch 2019 年 9 月 2 日
I tried that first but that way readtable is not able to detect the table structure of the file to import.
I have an excel-file with 6 rows to drop and then there is a timetable with headlines in row 7, dates in columns 1 (starting in row 8) and the actual data from (8,2) on. I want to import the timetable.
If I just load the data without specifieing the first rows to be dropped, all the cells are strings and I need to convert the cells in the table again, which is not so nice.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by