S = table(arrayfun(@(x)sprintf('Y%02d',x),(1:5)','un',0),[19;22;21;nan;19],...
[1;1;1;nan;1],{'','58.39','61.28','','63.55'},'VariableNames',...
{'PartID' 'Age' 'Sex','Test'});
M = { 'Males' [ 19] [ 20] [ 21] [ 22]
[ 97] [63.5500] [ 63] [62.4500] [61.9000]
[ 96] [62.3700] [61.8300] [61.2800] [60.7400]
[ 95] [61.1800] [60.6500] [60.1100] [59.5700]
[ 94] [59.9800] [59.4500] [58.9200] [58.3900]};
[ii,jj] = ndgrid([M{2:end,1}],[M{1,2:end}]);
M2 = [M{2:end,2:end}]';
mm = [jj(:),ones(numel(ii),1),M2(:),ii(:)];
mm1 = [S{:,{'Age','Sex'}},str2double(S({:,{'Test'}})];
[a,b,c] = intersect(mm1,mm(:,1:3),'rows');
out = sortrows([S.PartID(b),num2cell(mm(c,4))],1);
Best Answer