Create index vector from a grouping variable.
[G,GN] = nan_grp2idx(S) [G,GN,GL] = nan_grp2idx(S)
grouping variable, can be a numeric, or logical vector; a cell vector of strings; or a character matrix with each row representing a group label.
index vector taking integer values from 1 up to the number K of distinct groups
cell array of strings representing group labels. GN(G) reproduces S
same as GN, but GL has the same type as S
grp2idx treats NaNs or empty strings in S as missing values and returns NaNs in the corresponding rows of G. GN and GL don't include entries for missing values.
groups={'30s','40s','30s','40s','40s'}' [G,GN]=nan_grp2idx(groups) disp(GN(G))