Importing a table with unknown number of rows

조회 수: 18(최근 30일)
KAE
KAE 2021년 4월 16일
댓글: KAE 2021년 4월 18일
I have several xlsx files that contain the same columns, but different number of rows. An example xlsx file is attached. I would like to import them as tables, so I used Import Wizard to generate the attached function. The problem with the function is that it specifies the row length in opts.DataRange. However I would like to use this function on other xlxs files with the same columns, but different number of rows. How do I edit this function so it can accept any number of rows? Here's what I've tried,
dataLines = [2, Inf]; % Want to go from the 2th row to the last unknown row. Doesn't work.
opts.DataRange = "A" + dataLines(1, 1) + ":C" + dataLines(1, 2); % Columns A to C are imported from Excel file
but it crashes. I also tried
dataLines = [2, 500]; % I happen to know I always have less than 500 rows
but then my table actually has 500 rows, with the last several rows undesirably empty. I could manually delete them but I suspect there's a better way.

채택된 답변

Stephan
Stephan 2021년 4월 16일
I dont think it is needed to specify this, using readtable function. I never used this option to import a .csv-file as table in Matlab.
  댓글 수: 5
KAE
KAE 2021년 4월 18일
Thanks! I wonder why the Import Wizard function generation makes it so complicated? Well, serves me right for relying on it.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by