MATLAB: How to recognize gender by name

genderization by name in matlab

Hi!
I have a list (1 column, 601 rows) of the most popular male and female surnames and they are marked in another column as either M for male or F for female. I have another list of surnames of people from a statistical survey (which does not have the same dimensions as the list of names). I want to compare the names from the survey with the names in my list and mark them as either M or F if they are recognized. If they are not found in my list, I want to leave them blank. Does anyone know how I can do this?
Many thanks in advance.

Best Answer

Very easy to do:
%inputs:
%genderlist = Mx2 cell array, 1st column name, 2nd column gender
%namelist = Nx1 cell array, list of names that need gender
%output
%namelistwithgender = Nx2 cell array, 1st column from namelist, 2nd column corresponding gender if found in genderlist, empty otherwise
[isfound, where] = ismember(namelist, genderlist(:, 1));
namelistwithgender = namelist;
namelistwithgender(isfound, 2) = genderlist(where(isfound), 2);
Note that the search is performed case sensitive. If you want to ignore case, then convert both lists to lower in the ismember call.