MATLAB: Equivalent of isfield for tables isfieldtable I'd like to know if my Matlab table has a particular column. If it was a structure I'd use isfield. Is there a built in function for this? Best Answer I would also like to suggest using ismember()For instance:f1 = 1; f2 = 10; t = table(f1,f2)t = f1 f2 __ __ 1 10ismember('f1', t.Properties.VariableNames) logical 1It also works for a range of values:ismember({'f0','f1','f2'}, t.Properties.VariableNames) 1×3 logical array 0 1 1 Related SolutionsMATLAB: Does table creation produce error “VariableNames property must contain one name for each variable in the table” Just figured this out: have to use array2table, T = array2table(rand(30,8), ... 'VariableNames', {'var1' 'var2' 'var3' 'var4' 'var5' ... 'var6' 'var7' 'var8'});However if you want to assign other properties besides names, you have to do that separately, unlike the table command,T.Properties.VariableUnits = {'kg' 'm' 'W' 's' 'g' 'kg' 'm' 'W'}; MATLAB: Working with Excel Tables and Importing them. mask = ismember(YourTable.Properties.VariableNames, ListOfColumnsYouWant);NewTable = YourTable(:,mask); Related QuestionHow to check whether a column exist in a tableMake a table from a structureJoining 2 tables to make 1 tableHow to concatenate two columns in one table into one columnHow to assign a variable name to each column of a table composed by only one matrixMultiply a scalar to all column of a table
Best Answer