%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% train_test.m divides a walking data set into training and testing
% subsets.  It is called by average_new.m.  Odd-numbered gait
% cycles go to the training set while even-numbered gait cycles go
% to the testing set.
% 
%  Jared Markowitz
%  Summer 2011
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

train_r = 1:2:(size(n_ankle_ang_r,1)-1);
test_r  = 2:2:(size(n_ankle_ang_r,1)-1);
train_l = 1:2:(size(n_ankle_ang_l,1)-1);
test_l  = 2:2:(size(n_ankle_ang_l,1)-1);
train   = 1:2:(size(n_tib_ant_len,1)-1);
test    = 2:2:(size(n_tib_ant_len,1)-1);

m_ankle_ang_r  = mean(n_ankle_ang_r(train_r,:),1);  m_ankle_ang_l  = mean(n_ankle_ang_l(train_l,:),1);
m_ankle_mom_r  = mean(n_ankle_mom_r(train_r,:),1);  m_ankle_mom_l  = mean(n_ankle_mom_l(train_l,:),1);
m_ankle_vel_r  = mean(n_ankle_vel_r(train_r,:),1);  m_ankle_vel_l  = mean(n_ankle_vel_l(train_l,:),1);
m_ankle_work_r = mean(n_ankle_work_r(train_r,:),1); m_ankle_work_l = mean(n_ankle_work_l(train_l,:),1);
m_ankle_pow_r  = mean(n_ankle_pow_r(train_r,:),1);  m_ankle_pow_l  = mean(n_ankle_pow_l(train_l,:),1);
m_knee_ang_r   = mean(n_knee_ang_r(train_r,:),1);   m_knee_ang_l   = mean(n_knee_ang_l(train_l,:),1);
m_knee_mom_r   = mean(n_knee_mom_r(train_r,:),1);   m_knee_mom_l   = mean(n_knee_mom_l(train_l,:),1);
m_knee_vel_r   = mean(n_knee_vel_r(train_r,:),1);   m_knee_vel_l   = mean(n_knee_vel_l(train_l,:),1);
m_knee_work_r  = mean(n_knee_work_r(train_r,:),1);  m_knee_work_l  = mean(n_knee_work_l(train_l,:),1);
m_knee_pow_r   = mean(n_knee_pow_r(train_r,:),1);   m_knee_pow_l   = mean(n_knee_pow_l(train_l,:),1);
m_hip_ang_r    = mean(n_hip_ang_r(train_r,:),1);    m_hip_ang_l    = mean(n_hip_ang_l(train_l,:),1);
m_hip_mom_r    = mean(n_hip_mom_r(train_r,:),1);    m_hip_mom_l    = mean(n_hip_mom_l(train_l,:),1);
m_hip_vel_r    = mean(n_hip_vel_r(train_r,:),1);    m_hip_vel_l    = mean(n_hip_vel_l(train_l,:),1);
m_hip_work_r   = mean(n_hip_work_r(train_r,:),1);   m_hip_work_l   = mean(n_hip_work_l(train_l,:),1);
m_hip_pow_r    = mean(n_hip_pow_r(train_r,:),1);    m_hip_pow_l    = mean(n_hip_pow_l(train_l,:),1);

m_cop_l_x  = mean(n_cop_l_x(train_l,:),1);    m_cop_l_y  = mean(n_cop_l_y(train_l,:),1); 
m_cop_l_z  = mean(n_cop_l_z(train_l,:),1);    m_grf_l_x  = mean(n_grf_l_x(train_l,:),1); 
m_grf_l_y  = mean(n_grf_l_y(train_l,:),1);    m_grf_l_z  = mean(n_grf_l_z(train_l,:),1);
m_gtor_l_x = mean(n_gtor_l_x(train_l,:),1);   m_gtor_l_y = mean(n_gtor_l_y(train_l,:),1);
m_gtor_l_z = mean(n_gtor_l_z(train_l,:),1);   m_cop_r_x  = mean(n_cop_r_x(train_r,:),1);
m_cop_r_y  = mean(n_cop_r_y(train_r,:),1);    m_cop_r_z  = mean(n_cop_r_z(train_r,:),1); 
m_grf_r_x  = mean(n_grf_r_x(train_r,:),1);    m_grf_r_y  = mean(n_grf_r_y(train_r,:),1);
m_grf_r_z  = mean(n_grf_r_z(train_r,:),1);    m_gtor_r_x = mean(n_gtor_r_x(train_r,:),1);
m_gtor_r_y = mean(n_gtor_r_y(train_r,:),1);   m_gtor_r_z = mean(n_gtor_r_z(train_r,:),1);
m_com_l_x  = mean(n_com_l_x(train_l,:),1);    m_com_l_y  = mean(n_com_l_y(train_l,:),1);   
m_com_l_z  = mean(n_com_l_z(train_l,:),1);    m_com_r_x  = mean(n_com_r_x(train_r,:),1); 
m_com_r_y  = mean(n_com_r_y(train_r,:),1);    m_com_r_z  = mean(n_com_r_z(train_r,:),1); 

m_add_long_len = mean(n_add_long_len(train,:),1);   m_add_mag1_len = mean(n_add_mag1_len(train,:),1);   
m_add_mag2_len = mean(n_add_mag2_len(train,:),1);   m_add_mag3_len = mean(n_add_mag3_len(train,:),1);   
m_glut_med1_len = mean(n_glut_med1_len(train,:),1); m_glut_med2_len = mean(n_glut_med2_len(train,:),1);  
m_glut_med3_len = mean(n_glut_med3_len(train,:),1); m_glut_max1_len = mean(n_glut_max1_len(train,:),1);   
m_glut_max2_len = mean(n_glut_max2_len(train,:),1); m_glut_max3_len = mean(n_glut_max3_len(train,:),1);  
m_iliacus_len = mean(n_iliacus_len(train,:),1);     m_psoas_len = mean(n_psoas_len(train,:),1);      
m_semimem_len = mean(n_semimem_len(train,:),1);     m_semiten_len = mean(n_semiten_len(train,:),1);    
m_bi_fem_lh_len = mean(n_bi_fem_lh_len(train,:),1); m_rectus_fem_len = mean(n_rectus_fem_len(train,:),1);  
m_bi_fem_sh_len = mean(n_bi_fem_sh_len(train,:),1); m_vas_lat_len = mean(n_vas_lat_len(train,:),1);    
m_vas_med_len = mean(n_vas_med_len(train,:),1);     m_vas_int_len = mean(n_vas_int_len(train,:),1);    
m_gas_med_len = mean(n_gas_med_len(train,:),1);     m_gas_lat_len = mean(n_gas_lat_len(train,:),1);     
m_soleus_len = mean(n_soleus_len(train,:),1);       m_tib_ant_len = mean(n_tib_ant_len(train,:),1);    

m_add_long_ma_h = mean(n_add_long_ma_h(train,:),1);     m_add_mag1_ma_h = mean(n_add_mag1_ma_h(train,:),1);  
m_add_mag2_ma_h = mean(n_add_mag2_ma_h(train,:),1);     m_add_mag3_ma_h = mean(n_add_mag3_ma_h(train,:),1);  
m_glut_med1_ma_h = mean(n_glut_med1_ma_h(train,:),1);   m_glut_med2_ma_h = mean(n_glut_med2_ma_h(train,:),1); 
m_glut_med3_ma_h = mean(n_glut_med3_ma_h(train,:),1);   m_glut_max1_ma_h = mean(n_glut_max1_ma_h(train,:),1); 
m_glut_max2_ma_h = mean(n_glut_max2_ma_h(train,:),1);   m_glut_max3_ma_h = mean(n_glut_max3_ma_h(train,:),1); 
m_iliacus_ma_h = mean(n_iliacus_ma_h(train,:),1);       m_psoas_ma_h = mean(n_psoas_ma_h(train,:),1);     
m_semimem_ma_h = mean(n_semimem_ma_h(train,:),1);       m_semimem_ma_k = mean(n_semimem_ma_k(train,:),1);   
m_semiten_ma_h = mean(n_semiten_ma_h(train,:),1);       m_semiten_ma_k = mean(n_semiten_ma_k(train,:),1);   
m_bi_fem_lh_ma_h = mean(n_bi_fem_lh_ma_h(train,:),1);   m_bi_fem_lh_ma_k = mean(n_bi_fem_lh_ma_k(train,:),1); 
m_rectus_fem_ma_h = mean(n_rectus_fem_ma_h(train,:),1); m_rectus_fem_ma_k = mean(n_rectus_fem_ma_k(train,:),1);
m_bi_fem_sh_ma_k = mean(n_bi_fem_sh_ma_k(train,:),1);   m_vas_lat_ma_k = mean(n_vas_lat_ma_k(train,:),1);    
m_vas_med_ma_k = mean(n_vas_med_ma_k(train,:),1);       m_vas_int_ma_k = mean(n_vas_int_ma_k(train,:),1);    
m_gas_med_ma_k = mean(n_gas_med_ma_k(train,:),1);       m_gas_med_ma_a = mean(n_gas_med_ma_a(train,:),1);    
m_gas_lat_ma_k = mean(n_gas_lat_ma_k(train,:),1);       m_gas_lat_ma_a = mean(n_gas_lat_ma_a(train,:),1);    
m_soleus_ma_a = mean(n_soleus_ma_a(train,:),1);         m_tib_ant_ma_a = mean(n_tib_ant_ma_a(train,:),1);   

sd_ankle_ang_r  = std(n_ankle_ang_r(train_r,:),0,1);  sd_ankle_ang_l  = std(n_ankle_ang_l(train_l,:),0,1);
sd_ankle_mom_r  = std(n_ankle_mom_r(train_r,:),0,1);  sd_ankle_mom_l  = std(n_ankle_mom_l(train_l,:),0,1);
sd_ankle_vel_r  = std(n_ankle_vel_r(train_r,:),0,1);  sd_ankle_vel_l  = std(n_ankle_vel_l(train_l,:),0,1);
sd_ankle_work_r = std(n_ankle_work_r(train_r,:),0,1); sd_ankle_work_l = std(n_ankle_work_l(train_l,:),0,1);
sd_ankle_pow_r  = std(n_ankle_pow_r(train_r,:),0,1);  sd_ankle_pow_l  = std(n_ankle_pow_l(train_l,:),0,1);
sd_knee_ang_r   = std(n_knee_ang_r(train_r,:),0,1);   sd_knee_ang_l   = std(n_knee_ang_l(train_l,:),0,1);
sd_knee_mom_r   = std(n_knee_mom_r(train_r,:),0,1);   sd_knee_mom_l   = std(n_knee_mom_l(train_l,:),0,1);
sd_knee_vel_r   = std(n_knee_vel_r(train_r,:),0,1);   sd_knee_vel_l   = std(n_knee_vel_l(train_l,:),0,1);
sd_knee_work_r  = std(n_knee_work_r(train_r,:),0,1);  sd_knee_work_l  = std(n_knee_work_l(train_l,:),0,1);
sd_knee_pow_r   = std(n_knee_pow_r(train_r,:),0,1);   sd_knee_pow_l   = std(n_knee_pow_l(train_l,:),0,1);
sd_hip_ang_r    = std(n_hip_ang_r(train_r,:),0,1);    sd_hip_ang_l    = std(n_hip_ang_l(train_l,:),0,1);
sd_hip_mom_r    = std(n_hip_mom_r(train_r,:),0,1);    sd_hip_mom_l    = std(n_hip_mom_l(train_l,:),0,1);
sd_hip_vel_r    = std(n_hip_vel_r(train_r,:),0,1);    sd_hip_vel_l    = std(n_hip_vel_l(train_l,:),0,1);
sd_hip_work_r   = std(n_hip_work_r(train_r,:),0,1);   sd_hip_work_l   = std(n_hip_work_l(train_l,:),0,1);
sd_hip_pow_r    = std(n_hip_pow_r(train_r,:),0,1);    sd_hip_pow_l    = std(n_hip_pow_l(train_l,:),0,1);

sd_cop_l_x  = std(n_cop_l_x(train_l,:),0,1);    sd_cop_l_y  = std(n_cop_l_y(train_l,:),0,1); 
sd_cop_l_z  = std(n_cop_l_z(train_l,:),0,1);    sd_grf_l_x  = std(n_grf_l_x(train_l,:),0,1); 
sd_grf_l_y  = std(n_grf_l_y(train_l,:),0,1);    sd_grf_l_z  = std(n_grf_l_z(train_l,:),0,1);
sd_gtor_l_x = std(n_gtor_l_x(train_l,:),0,1);   sd_gtor_l_y = std(n_gtor_l_y(train_l,:),0,1);
sd_gtor_l_z = std(n_gtor_l_z(train_l,:),0,1);   sd_cop_r_x  = std(n_cop_r_x(train_r,:),0,1);
sd_cop_r_y  = std(n_cop_r_y(train_r,:),0,1);    sd_cop_r_z  = std(n_cop_r_z(train_r,:),0,1); 
sd_grf_r_x  = std(n_grf_r_x(train_r,:),0,1);    sd_grf_r_y  = std(n_grf_r_y(train_r,:),0,1);
sd_grf_r_z  = std(n_grf_r_z(train_r,:),0,1);    sd_gtor_r_x = std(n_gtor_r_x(train_r,:),0,1);
sd_gtor_r_y = std(n_gtor_r_y(train_r,:),0,1);   sd_gtor_r_z = std(n_gtor_r_z(train_r,:),0,1);
sd_com_l_x  = std(n_com_l_x(train_l,:),0,1);    sd_com_l_y  = std(n_com_l_y(train_l,:),0,1);   
sd_com_l_z  = std(n_com_l_z(train_l,:),0,1);    sd_com_r_x  = std(n_com_r_x(train_r,:),0,1); 
sd_com_r_y  = std(n_com_r_y(train_r,:),0,1);    sd_com_r_z  = std(n_com_r_z(train_r,:),0,1); 

sd_add_long_len = std(n_add_long_len(train,:),0,1);   sd_add_mag1_len = std(n_add_mag1_len(train,:),0,1);   
sd_add_mag2_len = std(n_add_mag2_len(train,:),0,1);   sd_add_mag3_len = std(n_add_mag3_len(train,:),0,1);   
sd_glut_med1_len = std(n_glut_med1_len(train,:),0,1); sd_glut_med2_len = std(n_glut_med2_len(train,:),0,1);  
sd_glut_med3_len = std(n_glut_med3_len(train,:),0,1); sd_glut_max1_len = std(n_glut_max1_len(train,:),0,1);   
sd_glut_max2_len = std(n_glut_max2_len(train,:),0,1); sd_glut_max3_len = std(n_glut_max3_len(train,:),0,1);  
sd_iliacus_len = std(n_iliacus_len(train,:),0,1);     sd_psoas_len = std(n_psoas_len(train,:),0,1);      
sd_semimem_len = std(n_semimem_len(train,:),0,1);     sd_semiten_len = std(n_semiten_len(train,:),0,1);    
sd_bi_fem_lh_len = std(n_bi_fem_lh_len(train,:),0,1); sd_rectus_fem_len = std(n_rectus_fem_len(train,:),0,1);  
sd_bi_fem_sh_len = std(n_bi_fem_sh_len(train,:),0,1); sd_vas_lat_len = std(n_vas_lat_len(train,:),0,1);    
sd_vas_med_len = std(n_vas_med_len(train,:),0,1);     sd_vas_int_len = std(n_vas_int_len(train,:),0,1);    
sd_gas_med_len = std(n_gas_med_len(train,:),0,1);     sd_gas_lat_len = std(n_gas_lat_len(train,:),0,1);     
sd_soleus_len = std(n_soleus_len(train,:),0,1);       sd_tib_ant_len = std(n_tib_ant_len(train,:),0,1);    

sd_add_long_ma_h = std(n_add_long_ma_h(train,:),0,1);     sd_add_mag1_ma_h = std(n_add_mag1_ma_h(train,:),0,1);  
sd_add_mag2_ma_h = std(n_add_mag2_ma_h(train,:),0,1);     sd_add_mag3_ma_h = std(n_add_mag3_ma_h(train,:),0,1);  
sd_glut_med1_ma_h = std(n_glut_med1_ma_h(train,:),0,1);   sd_glut_med2_ma_h = std(n_glut_med2_ma_h(train,:),0,1); 
sd_glut_med3_ma_h = std(n_glut_med3_ma_h(train,:),0,1);   sd_glut_max1_ma_h = std(n_glut_max1_ma_h(train,:),0,1); 
sd_glut_max2_ma_h = std(n_glut_max2_ma_h(train,:),0,1);   sd_glut_max3_ma_h = std(n_glut_max3_ma_h(train,:),0,1); 
sd_iliacus_ma_h = std(n_iliacus_ma_h(train,:),0,1);       sd_psoas_ma_h = std(n_psoas_ma_h(train,:),0,1);     
sd_semimem_ma_h = std(n_semimem_ma_h(train,:),0,1);       sd_semimem_ma_k = std(n_semimem_ma_k(train,:),0,1);   
sd_semiten_ma_h = std(n_semiten_ma_h(train,:),0,1);       sd_semiten_ma_k = std(n_semiten_ma_k(train,:),0,1);   
sd_bi_fem_lh_ma_h = std(n_bi_fem_lh_ma_h(train,:),0,1);   sd_bi_fem_lh_ma_k = std(n_bi_fem_lh_ma_k(train,:),0,1); 
sd_rectus_fem_ma_h = std(n_rectus_fem_ma_h(train,:),0,1); sd_rectus_fem_ma_k = std(n_rectus_fem_ma_k(train,:),0,1);
sd_bi_fem_sh_ma_k = std(n_bi_fem_sh_ma_k(train,:),0,1);   sd_vas_lat_ma_k = std(n_vas_lat_ma_k(train,:),0,1);    
sd_vas_med_ma_k = std(n_vas_med_ma_k(train,:),0,1);       sd_vas_int_ma_k = std(n_vas_int_ma_k(train,:),0,1);    
sd_gas_med_ma_k = std(n_gas_med_ma_k(train,:),0,1);       sd_gas_med_ma_a = std(n_gas_med_ma_a(train,:),0,1);    
sd_gas_lat_ma_k = std(n_gas_lat_ma_k(train,:),0,1);       sd_gas_lat_ma_a = std(n_gas_lat_ma_a(train,:),0,1);    
sd_soleus_ma_a = std(n_soleus_ma_a(train,:),0,1);         sd_tib_ant_ma_a = std(n_tib_ant_ma_a(train,:),0,1);   

tot_len_l = 0;
tot_len_r = 0;

ltemp = ankle_ang_l(train_l);
rtemp = ankle_ang_r(train_r);

for ll = 1:length(ltemp)
  tot_len_l = tot_len_l + length(ltemp{ll});
end;
for rr = 1:length(rtemp)
  tot_len_r = tot_len_r + length(rtemp{rr});
end;

m_stridetime_l = tot_len_l/length(ltemp)/Fs;
m_stridetime_r = tot_len_r/length(rtemp)/Fs;

clear tot_len_l tot_len_r;

path_out_train = ['~/Documents/MATLAB/data/' path1 '/processed/mot/mat/train'];

outfile_train  = [path_out_train '/' listfile '.mat'];

save(outfile_train,'m_*','sd_*','EMGleg','mass','leg_lengths');
clear m_* sd_*;

m_ankle_ang_r  = mean(n_ankle_ang_r(test_r,:),1);  m_ankle_ang_l  = mean(n_ankle_ang_l(test_l,:),1);
m_ankle_mom_r  = mean(n_ankle_mom_r(test_r,:),1);  m_ankle_mom_l  = mean(n_ankle_mom_l(test_l,:),1);
m_ankle_vel_r  = mean(n_ankle_vel_r(test_r,:),1);  m_ankle_vel_l  = mean(n_ankle_vel_l(test_l,:),1);
m_ankle_work_r = mean(n_ankle_work_r(test_r,:),1); m_ankle_work_l = mean(n_ankle_work_l(test_l,:),1);
m_ankle_pow_r  = mean(n_ankle_pow_r(test_r,:),1);  m_ankle_pow_l  = mean(n_ankle_pow_l(test_l,:),1);
m_knee_ang_r   = mean(n_knee_ang_r(test_r,:),1);   m_knee_ang_l   = mean(n_knee_ang_l(test_l,:),1);
m_knee_mom_r   = mean(n_knee_mom_r(test_r,:),1);   m_knee_mom_l   = mean(n_knee_mom_l(test_l,:),1);
m_knee_vel_r   = mean(n_knee_vel_r(test_r,:),1);   m_knee_vel_l   = mean(n_knee_vel_l(test_l,:),1);
m_knee_work_r  = mean(n_knee_work_r(test_r,:),1);  m_knee_work_l  = mean(n_knee_work_l(test_l,:),1);
m_knee_pow_r   = mean(n_knee_pow_r(test_r,:),1);   m_knee_pow_l   = mean(n_knee_pow_l(test_l,:),1);
m_hip_ang_r    = mean(n_hip_ang_r(test_r,:),1);    m_hip_ang_l    = mean(n_hip_ang_l(test_l,:),1);
m_hip_mom_r    = mean(n_hip_mom_r(test_r,:),1);    m_hip_mom_l    = mean(n_hip_mom_l(test_l,:),1);
m_hip_vel_r    = mean(n_hip_vel_r(test_r,:),1);    m_hip_vel_l    = mean(n_hip_vel_l(test_l,:),1);
m_hip_work_r   = mean(n_hip_work_r(test_r,:),1);   m_hip_work_l   = mean(n_hip_work_l(test_l,:),1);
m_hip_pow_r    = mean(n_hip_pow_r(test_r,:),1);    m_hip_pow_l    = mean(n_hip_pow_l(test_l,:),1);

m_cop_l_x  = mean(n_cop_l_x(test_l,:),1);    m_cop_l_y  = mean(n_cop_l_y(test_l,:),1); 
m_cop_l_z  = mean(n_cop_l_z(test_l,:),1);    m_grf_l_x  = mean(n_grf_l_x(test_l,:),1); 
m_grf_l_y  = mean(n_grf_l_y(test_l,:),1);    m_grf_l_z  = mean(n_grf_l_z(test_l,:),1);
m_gtor_l_x = mean(n_gtor_l_x(test_l,:),1);   m_gtor_l_y = mean(n_gtor_l_y(test_l,:),1);
m_gtor_l_z = mean(n_gtor_l_z(test_l,:),1);   m_cop_r_x  = mean(n_cop_r_x(test_r,:),1);
m_cop_r_y  = mean(n_cop_r_y(test_r,:),1);    m_cop_r_z  = mean(n_cop_r_z(test_r,:),1); 
m_grf_r_x  = mean(n_grf_r_x(test_r,:),1);    m_grf_r_y  = mean(n_grf_r_y(test_r,:),1);
m_grf_r_z  = mean(n_grf_r_z(test_r,:),1);    m_gtor_r_x = mean(n_gtor_r_x(test_r,:),1);
m_gtor_r_y = mean(n_gtor_r_y(test_r,:),1);   m_gtor_r_z = mean(n_gtor_r_z(test_r,:),1);
m_com_l_x  = mean(n_com_l_x(test_l,:),1);    m_com_l_y  = mean(n_com_l_y(test_l,:),1);   
m_com_l_z  = mean(n_com_l_z(test_l,:),1);    m_com_r_x  = mean(n_com_r_x(test_r,:),1); 
m_com_r_y  = mean(n_com_r_y(test_r,:),1);    m_com_r_z  = mean(n_com_r_z(test_r,:),1); 

m_add_long_len = mean(n_add_long_len(test,:),1);   m_add_mag1_len = mean(n_add_mag1_len(test,:),1);   
m_add_mag2_len = mean(n_add_mag2_len(test,:),1);   m_add_mag3_len = mean(n_add_mag3_len(test,:),1);   
m_glut_med1_len = mean(n_glut_med1_len(test,:),1); m_glut_med2_len = mean(n_glut_med2_len(test,:),1);  
m_glut_med3_len = mean(n_glut_med3_len(test,:),1); m_glut_max1_len = mean(n_glut_max1_len(test,:),1);   
m_glut_max2_len = mean(n_glut_max2_len(test,:),1); m_glut_max3_len = mean(n_glut_max3_len(test,:),1);  
m_iliacus_len = mean(n_iliacus_len(test,:),1);     m_psoas_len = mean(n_psoas_len(test,:),1);      
m_semimem_len = mean(n_semimem_len(test,:),1);     m_semiten_len = mean(n_semiten_len(test,:),1);    
m_bi_fem_lh_len = mean(n_bi_fem_lh_len(test,:),1); m_rectus_fem_len = mean(n_rectus_fem_len(test,:),1);  
m_bi_fem_sh_len = mean(n_bi_fem_sh_len(test,:),1); m_vas_lat_len = mean(n_vas_lat_len(test,:),1);    
m_vas_med_len = mean(n_vas_med_len(test,:),1);     m_vas_int_len = mean(n_vas_int_len(test,:),1);    
m_gas_med_len = mean(n_gas_med_len(test,:),1);     m_gas_lat_len = mean(n_gas_lat_len(test,:),1);     
m_soleus_len = mean(n_soleus_len(test,:),1);       m_tib_ant_len = mean(n_tib_ant_len(test,:),1);    

m_add_long_ma_h = mean(n_add_long_ma_h(test,:),1);     m_add_mag1_ma_h = mean(n_add_mag1_ma_h(test,:),1);  
m_add_mag2_ma_h = mean(n_add_mag2_ma_h(test,:),1);     m_add_mag3_ma_h = mean(n_add_mag3_ma_h(test,:),1);  
m_glut_med1_ma_h = mean(n_glut_med1_ma_h(test,:),1);   m_glut_med2_ma_h = mean(n_glut_med2_ma_h(test,:),1); 
m_glut_med3_ma_h = mean(n_glut_med3_ma_h(test,:),1);   m_glut_max1_ma_h = mean(n_glut_max1_ma_h(test,:),1); 
m_glut_max2_ma_h = mean(n_glut_max2_ma_h(test,:),1);   m_glut_max3_ma_h = mean(n_glut_max3_ma_h(test,:),1); 
m_iliacus_ma_h = mean(n_iliacus_ma_h(test,:),1);       m_psoas_ma_h = mean(n_psoas_ma_h(test,:),1);     
m_semimem_ma_h = mean(n_semimem_ma_h(test,:),1);       m_semimem_ma_k = mean(n_semimem_ma_k(test,:),1);   
m_semiten_ma_h = mean(n_semiten_ma_h(test,:),1);       m_semiten_ma_k = mean(n_semiten_ma_k(test,:),1);   
m_bi_fem_lh_ma_h = mean(n_bi_fem_lh_ma_h(test,:),1);   m_bi_fem_lh_ma_k = mean(n_bi_fem_lh_ma_k(test,:),1); 
m_rectus_fem_ma_h = mean(n_rectus_fem_ma_h(test,:),1); m_rectus_fem_ma_k = mean(n_rectus_fem_ma_k(test,:),1);
m_bi_fem_sh_ma_k = mean(n_bi_fem_sh_ma_k(test,:),1);   m_vas_lat_ma_k = mean(n_vas_lat_ma_k(test,:),1);    
m_vas_med_ma_k = mean(n_vas_med_ma_k(test,:),1);       m_vas_int_ma_k = mean(n_vas_int_ma_k(test,:),1);    
m_gas_med_ma_k = mean(n_gas_med_ma_k(test,:),1);       m_gas_med_ma_a = mean(n_gas_med_ma_a(test,:),1);    
m_gas_lat_ma_k = mean(n_gas_lat_ma_k(test,:),1);       m_gas_lat_ma_a = mean(n_gas_lat_ma_a(test,:),1);    
m_soleus_ma_a = mean(n_soleus_ma_a(test,:),1);         m_tib_ant_ma_a = mean(n_tib_ant_ma_a(test,:),1);   

sd_ankle_ang_r  = std(n_ankle_ang_r(test_r,:),0,1);  sd_ankle_ang_l  = std(n_ankle_ang_l(test_l,:),0,1);
sd_ankle_mom_r  = std(n_ankle_mom_r(test_r,:),0,1);  sd_ankle_mom_l  = std(n_ankle_mom_l(test_l,:),0,1);
sd_ankle_vel_r  = std(n_ankle_vel_r(test_r,:),0,1);  sd_ankle_vel_l  = std(n_ankle_vel_l(test_l,:),0,1);
sd_ankle_work_r = std(n_ankle_work_r(test_r,:),0,1); sd_ankle_work_l = std(n_ankle_work_l(test_l,:),0,1);
sd_ankle_pow_r  = std(n_ankle_pow_r(test_r,:),0,1);  sd_ankle_pow_l  = std(n_ankle_pow_l(test_l,:),0,1);
sd_knee_ang_r   = std(n_knee_ang_r(test_r,:),0,1);   sd_knee_ang_l   = std(n_knee_ang_l(test_l,:),0,1);
sd_knee_mom_r   = std(n_knee_mom_r(test_r,:),0,1);   sd_knee_mom_l   = std(n_knee_mom_l(test_l,:),0,1);
sd_knee_vel_r   = std(n_knee_vel_r(test_r,:),0,1);   sd_knee_vel_l   = std(n_knee_vel_l(test_l,:),0,1);
sd_knee_work_r  = std(n_knee_work_r(test_r,:),0,1);  sd_knee_work_l  = std(n_knee_work_l(test_l,:),0,1);
sd_knee_pow_r   = std(n_knee_pow_r(test_r,:),0,1);   sd_knee_pow_l   = std(n_knee_pow_l(test_l,:),0,1);
sd_hip_ang_r    = std(n_hip_ang_r(test_r,:),0,1);    sd_hip_ang_l    = std(n_hip_ang_l(test_l,:),0,1);
sd_hip_mom_r    = std(n_hip_mom_r(test_r,:),0,1);    sd_hip_mom_l    = std(n_hip_mom_l(test_l,:),0,1);
sd_hip_vel_r    = std(n_hip_vel_r(test_r,:),0,1);    sd_hip_vel_l    = std(n_hip_vel_l(test_l,:),0,1);
sd_hip_work_r   = std(n_hip_work_r(test_r,:),0,1);   sd_hip_work_l   = std(n_hip_work_l(test_l,:),0,1);
sd_hip_pow_r    = std(n_hip_pow_r(test_r,:),0,1);    sd_hip_pow_l    = std(n_hip_pow_l(test_l,:),0,1);

sd_cop_l_x  = std(n_cop_l_x(test_l,:),0,1);    sd_cop_l_y  = std(n_cop_l_y(test_l,:),0,1); 
sd_cop_l_z  = std(n_cop_l_z(test_l,:),0,1);    sd_grf_l_x  = std(n_grf_l_x(test_l,:),0,1); 
sd_grf_l_y  = std(n_grf_l_y(test_l,:),0,1);    sd_grf_l_z  = std(n_grf_l_z(test_l,:),0,1);
sd_gtor_l_x = std(n_gtor_l_x(test_l,:),0,1);   sd_gtor_l_y = std(n_gtor_l_y(test_l,:),0,1);
sd_gtor_l_z = std(n_gtor_l_z(test_l,:),0,1);   sd_cop_r_x  = std(n_cop_r_x(test_r,:),0,1);
sd_cop_r_y  = std(n_cop_r_y(test_r,:),0,1);    sd_cop_r_z  = std(n_cop_r_z(test_r,:),0,1); 
sd_grf_r_x  = std(n_grf_r_x(test_r,:),0,1);    sd_grf_r_y  = std(n_grf_r_y(test_r,:),0,1);
sd_grf_r_z  = std(n_grf_r_z(test_r,:),0,1);    sd_gtor_r_x = std(n_gtor_r_x(test_r,:),0,1);
sd_gtor_r_y = std(n_gtor_r_y(test_r,:),0,1);   sd_gtor_r_z = std(n_gtor_r_z(test_r,:),0,1);
sd_com_l_x  = std(n_com_l_x(test_l,:),0,1);    sd_com_l_y  = std(n_com_l_y(test_l,:),0,1);   
sd_com_l_z  = std(n_com_l_z(test_l,:),0,1);    sd_com_r_x  = std(n_com_r_x(test_r,:),0,1); 
sd_com_r_y  = std(n_com_r_y(test_r,:),0,1);    sd_com_r_z  = std(n_com_r_z(test_r,:),0,1); 

sd_add_long_len = std(n_add_long_len(test,:),0,1);   sd_add_mag1_len = std(n_add_mag1_len(test,:),0,1);   
sd_add_mag2_len = std(n_add_mag2_len(test,:),0,1);   sd_add_mag3_len = std(n_add_mag3_len(test,:),0,1);   
sd_glut_med1_len = std(n_glut_med1_len(test,:),0,1); sd_glut_med2_len = std(n_glut_med2_len(test,:),0,1);  
sd_glut_med3_len = std(n_glut_med3_len(test,:),0,1); sd_glut_max1_len = std(n_glut_max1_len(test,:),0,1);   
sd_glut_max2_len = std(n_glut_max2_len(test,:),0,1); sd_glut_max3_len = std(n_glut_max3_len(test,:),0,1);  
sd_iliacus_len = std(n_iliacus_len(test,:),0,1);     sd_psoas_len = std(n_psoas_len(test,:),0,1);      
sd_semimem_len = std(n_semimem_len(test,:),0,1);     sd_semiten_len = std(n_semiten_len(test,:),0,1);    
sd_bi_fem_lh_len = std(n_bi_fem_lh_len(test,:),0,1); sd_rectus_fem_len = std(n_rectus_fem_len(test,:),0,1);  
sd_bi_fem_sh_len = std(n_bi_fem_sh_len(test,:),0,1); sd_vas_lat_len = std(n_vas_lat_len(test,:),0,1);    
sd_vas_med_len = std(n_vas_med_len(test,:),0,1);     sd_vas_int_len = std(n_vas_int_len(test,:),0,1);    
sd_gas_med_len = std(n_gas_med_len(test,:),0,1);     sd_gas_lat_len = std(n_gas_lat_len(test,:),0,1);     
sd_soleus_len = std(n_soleus_len(test,:),0,1);       sd_tib_ant_len = std(n_tib_ant_len(test,:),0,1);    

sd_add_long_ma_h = std(n_add_long_ma_h(test,:),0,1);     sd_add_mag1_ma_h = std(n_add_mag1_ma_h(test,:),0,1);  
sd_add_mag2_ma_h = std(n_add_mag2_ma_h(test,:),0,1);     sd_add_mag3_ma_h = std(n_add_mag3_ma_h(test,:),0,1);  
sd_glut_med1_ma_h = std(n_glut_med1_ma_h(test,:),0,1);   sd_glut_med2_ma_h = std(n_glut_med2_ma_h(test,:),0,1); 
sd_glut_med3_ma_h = std(n_glut_med3_ma_h(test,:),0,1);   sd_glut_max1_ma_h = std(n_glut_max1_ma_h(test,:),0,1); 
sd_glut_max2_ma_h = std(n_glut_max2_ma_h(test,:),0,1);   sd_glut_max3_ma_h = std(n_glut_max3_ma_h(test,:),0,1); 
sd_iliacus_ma_h = std(n_iliacus_ma_h(test,:),0,1);       sd_psoas_ma_h = std(n_psoas_ma_h(test,:),0,1);     
sd_semimem_ma_h = std(n_semimem_ma_h(test,:),0,1);       sd_semimem_ma_k = std(n_semimem_ma_k(test,:),0,1);   
sd_semiten_ma_h = std(n_semiten_ma_h(test,:),0,1);       sd_semiten_ma_k = std(n_semiten_ma_k(test,:),0,1);   
sd_bi_fem_lh_ma_h = std(n_bi_fem_lh_ma_h(test,:),0,1);   sd_bi_fem_lh_ma_k = std(n_bi_fem_lh_ma_k(test,:),0,1); 
sd_rectus_fem_ma_h = std(n_rectus_fem_ma_h(test,:),0,1); sd_rectus_fem_ma_k = std(n_rectus_fem_ma_k(test,:),0,1);
sd_bi_fem_sh_ma_k = std(n_bi_fem_sh_ma_k(test,:),0,1);   sd_vas_lat_ma_k = std(n_vas_lat_ma_k(test,:),0,1);    
sd_vas_med_ma_k = std(n_vas_med_ma_k(test,:),0,1);       sd_vas_int_ma_k = std(n_vas_int_ma_k(test,:),0,1);    
sd_gas_med_ma_k = std(n_gas_med_ma_k(test,:),0,1);       sd_gas_med_ma_a = std(n_gas_med_ma_a(test,:),0,1);    
sd_gas_lat_ma_k = std(n_gas_lat_ma_k(test,:),0,1);       sd_gas_lat_ma_a = std(n_gas_lat_ma_a(test,:),0,1);    
sd_soleus_ma_a = std(n_soleus_ma_a(test,:),0,1);         sd_tib_ant_ma_a = std(n_tib_ant_ma_a(test,:),0,1);   

tot_len_l = 0;
tot_len_r = 0;

ltemp = ankle_ang_l(test_l);
rtemp = ankle_ang_r(test_r);

for ll = 1:length(ltemp)
  tot_len_l = tot_len_l + length(ltemp{ll});
end;
for rr = 1:length(rtemp)
  tot_len_r = tot_len_r + length(rtemp{rr});
end;

m_stridetime_l = tot_len_l/length(ltemp)/Fs;
m_stridetime_r = tot_len_r/length(rtemp)/Fs;

path_out_test = ['~/Documents/MATLAB/data/' path1 '/processed/mot/mat/test'];

outfile_test  = [path_out_test '/' listfile '.mat'];

save(outfile_test,'m_*','sd_*','EMGleg','mass','leg_lengths');
clear m_* sd_*;