MATLAB: How to extract a subtable by rownames MATLAB Hi, I have a table of 10 columns and one column represent last names. I would like to extract all the rows that belong to one last name. How to do that? Thanks in advance. Jennifer Best Answer Modifying the example on this documentation page a bit:% Make a patients tableload patientspatients = table(Age,Gender,Height,Weight,Smoker,... 'RowNames',LastName);% Give each patient a random first name bloggers = {'Cleve'; 'Loren'; 'Guy'; 'Steve'; 'Stuart'; 'Hans'};n = numel(bloggers);p = size(patients, 1);patients.FirstName = bloggers (randi([1 n], p, 1));% Retrieve all patients named Steve using logical indexingpatientsNamedSteve = patients(strcmp(patients.FirstName, 'Steve'), :);% There shouldn't be any patients named Aaron; check using logical indexingpatientsNamedAaron = patients(strcmp(patients.FirstName, 'Aaron'), :)isempty(patientsNamedAaron) % true Related SolutionsMATLAB: How do you order table columns based on a vector with their names This can be done by indexing into the table with the "order" cell.Note: Table columns cannot repeat names so "Age" will only appear once, and all subsequent ones will have the value "Age_1", "Age_2"... >> patients2 = patients(:,order) MATLAB: How do we take user’s input for table name and column name and then extract corresponding values from the table Please refer to the following example script. It asks users to input table name and column name. Then it takes out the column based on the input.load patientsT = table(Gender,Smoker,Height,Weight);TableName = input('table name:');ColumnName = input('column name:', 's');TableName.(ColumnName) Related QuestionHow do you find and replace rows in two tables with some variables in commonFind matched string in tableHow to display a MATLAB table in a figure and make it boldMultiply/divided two tablesHow to set the title of a uitableDoes the ‘CellEditCallback’ not get fired when a uitable has a table variable as its ‘Data’ on MATLAB R2018aWorking with missing table data
Best Answer