Searching a cell array of percentile scores based on age and gender
    5 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Daniel
 am 28 Mai 2015
  
    
    
    
    
    Kommentiert: Daniel
 am 1 Jun. 2015
            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
0 Kommentare
Akzeptierte Antwort
  Andrei Bobrov
      
      
 am 29 Mai 2015
        
      Bearbeitet: Andrei Bobrov
      
      
 am 29 Mai 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 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
				Mehr zu Fit Postprocessing finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


