Importing a table with unknown number of rows
5 views (last 30 days)
Show older comments
KAE on 16 Apr 2021
Commented: KAE on 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.
Stephan on 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.
More Answers (0)
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!