Importing a table with unknown number of rows

12 Ansichten (letzte 30 Tage)
KAE am 16 Apr. 2021
Kommentiert: KAE am 18 Apr. 2021
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.

Akzeptierte Antwort

Stephan am 16 Apr. 2021
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 Kommentare
KAE am 18 Apr. 2021
Thanks! I wonder why the Import Wizard function generation makes it so complicated? Well, serves me right for relying on it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)


Mehr zu Tables finden Sie in Help Center und File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by