MATLAB: How to make a variable that is equal to the position of a row in a table by using the name of that row

rowstables

I have this
find(ismember(fieldnames(T), 'Name of Column'))
Where T is a table with named rows and columns, if I enter the name of a column it gives me a number equal to the position of that column, but it does not work for rows. How could I make this work for rows as well?

Best Answer

fieldnames is specically documented for struct or Java or COM objects at least thru R2019b; I wasn't aware it would return the column names from a table object. There's no parallel for the row identifiers like rownames however.
fieldnames seems to return the table variable names first and is followed by the elements {'Properties','Row','Variables'} irrespective of the values of those additional property values. Hence, it's not particularly useful for that purpose.
But, it's simple enough, just use the table .Row property...
find(ismember(T.Row, 'Name of Row'))
There is also the T.Properties.RowNames property that returns the row names cellstr array.
I tend to write using newer string class functions like contains or beginsWith instead of ismember although the row names internally are and are returned as a cellstr array.