To list all the male names in Matlab, assuming that you have a cell array of names called names
, you can use the strcmp
function to compare each name to the string "male", creating a logical array of true/false values. You can then use this logical array to index the names
cell array and extract only the names where the logical value is true
. Here is the code block that accomplishes this:
main.m303 chars9 lines
The resulting male_names
variable will contain a cell array of all the male names in the names
variable.
gistlibby LogSnag