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

조회 수: 1 (최근 30일)
Daniel
Daniel 2015년 5월 28일
댓글: Daniel 2015년 6월 1일
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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2015년 5월 29일
편집: Andrei Bobrov 2015년 5월 29일
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
Andrei Bobrov
Andrei Bobrov 2015년 5월 29일
편집: Andrei Bobrov 2015년 5월 29일
corrected
Daniel
Daniel 2015년 6월 1일
Thank you very much for the help

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Katarzyna Wieciorek
Katarzyna Wieciorek 2015년 5월 29일
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!

Translated by