Searching a cell array of percentile scores based on age and gender

1 view (last 30 days)
I have one table in matlab and two cell arrays. The table is a list of ID numbers, age, sex, and test scores. The second two cell arrays are percentile rankings, one table for males and the other for females. What I am trying to do first is use the sex to select the correct percentile rankings array. Then, using the age, find the correct column. The ages are located in row 1. Then within that column find the matching score. Once the matching score is found the percentile ranking is in the first column for that row.
This is an example of the Subject table
PartID Age Sex Test
_______ ____ ___ __________
'Y01' 19 1 ''
'Y02' 22 1 '58.39'
'Y03' 21 1 '61.28'
'Y04' NaN NaN ''
'Y05' 19 1 '63.55'
This is an example of the male percentile table. Ages are in Row 1 and percentile rankings are Column 1. The inside of the array is the test scores.
'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]
For subject Y02 it would determine they had a percentile of 94. Y03 would be 96. Y05 would be 97. Then any subject with a missing value would be skipped.
Any suggestions on how to accomplish this?
Thank you

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 29 May 2015
Edited: Andrei Bobrov on 29 May 2015
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);
  3 Comments

Sign in to comment.

More Answers (1)

Katarzyna Wieciorek
Katarzyna Wieciorek on 29 May 2015
I would try find
[row,col] = find(X==score(id)) and extract percentile from this row in column 1 if col corresponds to age
for skipping you need if else

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!