Reading a table in excel

I am having some trouble with reading a table in excel and then extracting specific rows.
I first use:
filenameEGI='Copy of EGI Yield Data July 2020 7_30_20.xlsx'
fileread=readtable(filenameEGI)
columnData=fileread(2056:2098,:)
In effort to read rows 2056 to 2098. However in certain columns NaN is bein displayed and I would like whatever was in that excel cell to display instead.
Where the NaN displayed, in the excel cell it displayed words and file folder links.
Any suggestions or application of corrections?

4 Comments

Can you share your data file? What version of MATLAB are you using?
Readtable creates a table. Each column in a table in a unique variable. Variables can only contain values of the same data type. If some rows contain text and some contain numbers, MATLAB will select one data type. The rows that are not of that data type get read in as missing (NaN for numbers).
If each column contains the same type of data, then it is a matter of setting the data type correctly. You might first try importing your file interactively using the Import Tool. You might also find this video from our Exploratory Data Analysis course on Coursera helpful.
not sure. but I think table does not support strings. use csvread instead.
table does support characters, but csvread() does not.
Columns that contain a mix of numbers and text will generally be detected as text, but that depends upon the release and the fraction of text. Older releases that did not automatically use detectImportOptions were more likely to guess that a file with leading numbers would never have text; detectImportOptions goes a better job of figuring out columns.
You could consider using readcell() : the entries that can be converted to numeric will be converted, but will be left in individual cells.
You can then use cellfun(@isnumeric) or similar to locate non-numeric entries.

Sign in to comment.

Answers (0)

Asked:

on 12 Aug 2020

Commented:

on 12 Aug 2020

Community Treasure Hunt

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

Start Hunting!