Interating through a table data set
    6 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Andrew Czeizler
 el 5 de Mzo. de 2019
  
    
    
    
    
    Respondida: Andrew Czeizler
 el 7 de Mzo. de 2019
            Hi all,
Im trying to learn how to isolate data from control statements in a table.
Observe the below code -
I am getting some strange results.
Any help would be very much appreciated.
Best,
Andrew
age = input("please input the age: ");
sex=input("please input the gender (M/F):", 's');
%create tables%
%age table
agelow=[30;35;40;45;50;55;60;65; 70];
agehigh= [34;39; 44;49;54;59;64;69;74];
pointsfemale =[-9;-4;0;3;6;7;8;8;8];
pointsmale = [-1; 0; 1; 2 ; 3; 4; 5; 6 ; 7];
agetable=table(agelow, agehigh, pointsfemale, pointsmale)
%if age >= agelow & age<=agehigh & sex== 'F'
for row = 1:height(agetable)
    if  age >=agelow & age <=agehigh & sex =='F'
        test=agetable{row,pointsfemale}
    else 
        test=agetable{row, pointsmale}
    end
end
0 comentarios
Respuesta aceptada
  Andrei Bobrov
      
      
 el 5 de Mzo. de 2019
        
      Editada: Andrei Bobrov
      
      
 el 5 de Mzo. de 2019
  
      sex = {'F';'M'};
age = [55;40];
[~,~,ii] = histcounts(age,agetable.agelow);
[lo,jj] = ismember(sex,{'F','M'});
at = agetable{:,3:4};
test = at(sub2ind(size(at),ii,jj(lo)));
0 comentarios
Más respuestas (4)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

