Function to import Excel files with different lengths

12 views (last 30 days)
Hi everyone,
I am trying to do a matlab function in order to automate the import of Excel files (databases with the same template) that have a different number of rows.
I used the "import data" tool and selected the number of colums that I needed. Then I generated a function.
I introduced a new variable 'endoffile' to this function because I would like to generalize it: for instance, I do not want dataLines = [3,30] but dataLines = [3, endoffile]. I would like that this function calculats the numbers of full rows.
I created a while loop that have this condition : blabla ~= "". I have a lot of errors unfortunately (all kinds of errors).
Could you please help me to think about the code that would help me to write this function?
Thanks,
Have a nice day
  5 Comments
Pranav Verma
Pranav Verma on 12 Apr 2021
Hi Lorys,
Could you please share more information about how many excel sheets you are trying to import, how does the sheets look and whether you want to import all the rows or a subset of them.
Thanks
dpb
dpb on 12 Apr 2021
"The problem is that the first column (Week) has more cells fill than the others.."
If you haven't taken the previous hint and built an import options object and used it for all files following the template, then I strongly suggest you do so.
In particular, setting
'MissingRule','omitrow'
will likely fix the problem on import when it runs out of data for the other columns besides the date.
Even if that doesn't work uniquely, it's still no problem to just import what you get and then programmatically delete the rows at the end you don't want.
Don't obsess over finding the last used row in the spreadsheet with all cells full; it's just not the way to solve the problem.

Sign in to comment.

Answers (0)

Categories

Find more on Data Import from MATLAB 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!