How do I determine if a column header exists in a table?
Show older comments
I am performing a readtable() command. Sometimes the table contains a column called "x"; sometimes it is called "y". How would you determine if one column exists or not. I looked through the is* functions but did not see anything that I could use in an if statement.
Answers (1)
I would access the table varaible names and check if 'x' is a member or not.
T = readtable('patients.xls')
varNm = T.Properties.VariableNames
any(ismember('X',varNm))
Categories
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!