>> load patients>> whos Gender Height Name Size Bytes Class Attributes Gender 100x1 12212 cell Height 100x1 800 double >> G = findgroups(Gender);>> splitapply(@mean,Height,G)ans = 6.5151e+01 6.9234e+01
At this point, the doc page says: "The first row of the output argument is the mean height of the female patients, and the second row is the mean height of the male patients." But it doesn't say how to determine that is, in fact, the case. In other words, how can I tell that G ordered the group variables as female followed by male, rather than the opposite. The doc page for findgroups basically suggests to use a visual inspection of G, but that's not practical for large arrays with lots of groups. Also, I'd like to be able to get the group variables out from Gender in the same order that they correspond to the output from splitapply, e.g., for plotting or axis labeling. So far, I've come up with this
>> Gvar = splitapply(@(x)(x(1)),Gender,G)Gvar = 2×1 cell array {'Female'} {'Male' }
Is there not a Matlab-provided function to do this? If so, I couldn't find it and was surprised as it seems to me that this would be a pretty common need.
Best Answer