How to get all the individuals in a table with a certain string value
15 views (last 30 days)
Show older comments
If i have a table with some variables A,B,C... i would like to know how to get all the individuals that have the same string value por a variable. For example, lets say A is Gender; i would like to know how to get all the rows that have 'Male' or 'Female' on the Gender column.
0 Comments
Answers (1)
Star Strider
on 6 Dec 2021
.
5 Comments
Star Strider
on 6 Dec 2021
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Steven Lord
on 6 Dec 2021
You could also use string or categorical operations.
load patients
T = table(LastName, Gender, Smoker);
T.Gender = categorical(T.Gender); % Change from cellstr to categorical
head(T)
allMales = T(T.Gender == 'Male', :) % 'Male' converted to categorical for comparison
allSmiths = T(T.LastName == "Smith", :) % "Smith" is a string
allStartsWithW = T(startsWith(T.LastName, "W"), :) % Can perform other string ops
See Also
Categories
Find more on Data Type Conversion 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!