How to figure out the number of rows for headers?
Show older comments
I have Excel files with unknown number of headers. For exmple, some files only have one row of header info. Another one could have 12 header lines.
I would need to know the accurate count of the number of rows of headerlines, so that my program would know the Excel Row# for a cetain data value. Right now, it only knows the relative Row # of the numerical portion of the Excel file.
What makes things more complicated is that my data also routinely contain columns that are made of text-strings.
Right now, I use readtable to read the Excel file. It basically assume the first Row is the headerline, and the rest of them are data. Here is my question. Is there a straightforward way to identify the number of headerlines in my case?
Thanks!
1 Comment
Leon
on 2 Apr 2020
Answers (2)
Fangjun Jiang
on 30 Mar 2020
0 votes
If you use [Num, Txt, Raw]=xlsread(), can you figure it out based on the numerical, text and raw data?
Josh Zagorski
on 30 Mar 2020
0 votes
[A DELIM NHEADERLINES] = importdata(...) returns the detected number of header
lines in the input ASCII file.
So, [Matrix_converted,'delimiter',No_headerlines = importdata('file.xlsx');
5 Comments
Leon
on 30 Mar 2020
Josh Zagorski
on 30 Mar 2020
Edited: Josh Zagorski
on 30 Mar 2020
For ASCII files, data contains a double array. Other fields contain cell arrays of character vectors. textdata includes row and column headers.
For spreadsheets, each field contains a struct, with one field for each worksheet.
I'm using it to load .csv and .xlsx files
Leon
on 31 Mar 2020
Josh Zagorski
on 31 Mar 2020
Do you have the correct filepath?
Otherwise, I glossed over your "text-strings" data comment - wondering if data needs to be double/numeric "data contains a double array."
Leon
on 2 Apr 2020
Categories
Find more on Spreadsheets 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!