function plot_musc(list,speeds,uaseleg,save_dir)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% plot_musc.m produces plots that compare the mechanical variables of
% different subjects during walking.  The plots include error bars
% and have the data for each requested subject on one plot.
%
% Inputs:
% list     - list of subjects
% speeds   - vector of requested speeds
% useleg   - leg for which to plot ('L','R', or 'EMG').
% save_dir - directory to save files (leave blank to not save)
%
% Outputs:
% Just plots.
% 
% Example Usage: plot_musc(['AM062411';'AD052611';'EM072611'],[125 150],'EMG','~/Desktop')
%
% Jared Markowitz
% Summer 2011
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%colors = ['b';'r';'k';'m';'g';'c';'y'];

colors = [0.0 0.0 0.0;
          0.0 0.0 1.0;
          1.0 0.0 0.0;
          0.0 0.5 0.2;
          0.5 0.0 1.0;
          1.0 0.6 0.0;
          0.4 0.4 0.4
          0.0 0.1 0.5;
          .95 .85 0.0;
          0.8 0.0 0.8;
          .45 0.3 0.0
          0.0 0.3 0.1];

addpath('~/Dropbox/harvard/processMOT');
close all;
numpts = 101;
leg_cmd = 'legend(''';
for h = 1:size(list,1)
  if h < size(list,1)
    leg_cmd = [leg_cmd list(h,:) ''',''']; 
  else
    leg_cmd = [leg_cmd list(h,:) ''',''location'',''best'');'];
  end;  
end;

for i = 1:size(speeds,2)
  if speeds(i) == 75;
    numstr = '075';
  else
    numstr = num2str(speeds(i));
  end;
  
  for j= 1:size(list,1)
    path_full = ['~/Documents/MATLAB/data/' list(j,:) '/processed/mot/mat/all/'];
    eval(['load ' path_full 'walk' numstr '.mat']);

    if exist('useleg')==0 || strcmp(useleg,'EMG')==1
      useleg1 = EMGleg;
    else
      useleg1 = useleg;
    end;
  
    subplot(3,2,1)   
    niceBars(0:(numpts-1),m_tib_ant_len,sd_tib_ant_len,colors(1,:),0.5);
    hold on;
    niceBars(0:(numpts-1),m_soleus_len,sd_soleus_len,colors(2,:),0.5);  
    hold on;
    niceBars(0:(numpts-1),m_gas_med_len,sd_gas_med_len,colors(3,:),0.5);   
    axis tight;
    xlabel('Percent GC','fontsize',14);
    ylabel('lmtc','fontsize',14);
    title('Ankle lmtc','fontsize',14);
    legend('TA','SOL','GAS','location','eastoutside');
    h_xlabel = get(gca,'XLabel');
    set(h_xlabel,'FontSize',14); 
    h_ylabel = get(gca,'YLabel');
    set(h_ylabel,'FontSize',14); 
    h_title = get(gca,'Title');
    set(h_title,'FontSize',14); 
    set(gca,'fontsize',14)
    set(gca,'linewidth',2)
    subplot(3,2,2)  
    niceBars(0:(numpts-1),m_tib_ant_ma_a,sd_tib_ant_ma_a,colors(1,:),0.5);
    hold on;
    niceBars(0:(numpts-1),m_soleus_ma_a,sd_soleus_ma_a,colors(2,:),0.5);  
    hold on;
    niceBars(0:(numpts-1),m_gas_med_ma_a,sd_gas_med_ma_a,colors(3,:),0.5);   
    axis tight;
    xlabel('Percent GC','fontsize',14);
    ylabel('Mom. Arms','fontsize',14);
    title('Ankle Mom. Arms','fontsize',14);
    legend('TA','SOL','GAS','location','eastoutside');        
    h_xlabel = get(gca,'XLabel');
    set(h_xlabel,'FontSize',14); 
    h_ylabel = get(gca,'YLabel');
    set(h_ylabel,'FontSize',14); 
    h_title = get(gca,'Title');
    set(h_title,'FontSize',14); 
    set(gca,'fontsize',14)
    set(gca,'linewidth',2)
    subplot(3,2,3)
    niceBars(0:(numpts-1),m_gas_med_len,sd_gas_med_len,colors(1,:),0.5);
    hold on;
    niceBars(0:(numpts-1),m_vas_lat_len,sd_vas_lat_len,colors(2,:),0.5);  
    hold on;
    niceBars(0:(numpts-1),m_bi_fem_sh_len,sd_bi_fem_sh_len,colors(3,:),0.5);     
    hold on;
    niceBars(0:(numpts-1),m_rectus_fem_len,sd_rectus_fem_len,colors(4,:),0.5);  
    hold on;
    niceBars(0:(numpts-1),m_semimem_len,sd_semimem_len,colors(5,:),0.5);  
    axis tight;
    xlabel('Percent GC','fontsize',14);
    ylabel('lmtc','fontsize',14);
    title('Knee lmtc','fontsize',14);
    legend('GAS','VAS','BFSH','RF','HAM','location','eastoutside');        
    h_xlabel = get(gca,'XLabel');
    set(h_xlabel,'FontSize',14); 
    h_ylabel = get(gca,'YLabel');
    set(h_ylabel,'FontSize',14); 
    h_title = get(gca,'Title');
    set(h_title,'FontSize',14); 
    set(gca,'fontsize',14)
    set(gca,'linewidth',2)
    subplot(3,2,4)
    niceBars(0:(numpts-1),m_gas_med_ma_k,sd_gas_med_ma_k,colors(1,:),0.5);
    hold on;
    niceBars(0:(numpts-1),m_vas_lat_ma_k,sd_vas_lat_ma_k,colors(2,:),0.5);  
    hold on;
    niceBars(0:(numpts-1),m_bi_fem_sh_ma_k,sd_bi_fem_sh_ma_k,colors(3,:),0.5);     
    hold on;
    niceBars(0:(numpts-1),m_rectus_fem_ma_k,sd_rectus_fem_ma_k,colors(4,:),0.5);  
    hold on;
    niceBars(0:(numpts-1),m_semimem_ma_k,sd_semimem_ma_k,colors(5,:),0.5);  
    axis tight;
    xlabel('Percent GC','fontsize',14);
    ylabel('Mom. Arms','fontsize',14);
    title('Knee Mom. Arms','fontsize',14);
    legend('GAS','VAS','BFSH','RF','HAM','location','eastoutside');    
    h_xlabel = get(gca,'XLabel');
    set(h_xlabel,'FontSize',14); 
    h_ylabel = get(gca,'YLabel');
    set(h_ylabel,'FontSize',14); 
    h_title = get(gca,'Title');
    set(h_title,'FontSize',14); 
    set(gca,'fontsize',14)
    set(gca,'linewidth',2)
    subplot(3,2,5)
    niceBars(0:(numpts-1),m_rectus_fem_len,sd_rectus_fem_len,colors(1,:),0.5);
    hold on;
    niceBars(0:(numpts-1),m_semimem_len,sd_semimem_len,colors(2,:),0.5);  
    hold on;
    niceBars(0:(numpts-1),m_iliacus_len,sd_iliacus_len,colors(3,:),0.5);     
    hold on;
    niceBars(0:(numpts-1),m_glut_max2_len,sd_glut_max2_len,colors(4,:),0.5);  
    hold on;
    niceBars(0:(numpts-1),m_glut_med3_len,sd_glut_med3_len,colors(5,:),0.5);  
    hold on;    
    niceBars(0:(numpts-1),m_add_long_len,sd_add_long_len,colors(6,:),0.5);  
    hold on;    
    niceBars(0:(numpts-1),m_add_mag2_len,sd_add_mag2_len,colors(7,:),0.5);  
    axis tight;
    xlabel('Percent GC','fontsize',14);
    ylabel('lmtc','fontsize',14);
    title('Hip lmtc','fontsize',14);
    legend('RF','HAM','ILL','GMAX','GMED','ADDL','ADDM','location','eastoutside');            
    h_xlabel = get(gca,'XLabel');
    set(h_xlabel,'FontSize',14); 
    h_ylabel = get(gca,'YLabel');
    set(h_ylabel,'FontSize',14); 
    h_title = get(gca,'Title');
    set(h_title,'FontSize',14); 
    set(gca,'fontsize',14)
    set(gca,'linewidth',2)
    subplot(3,2,6)
    niceBars(0:(numpts-1),m_rectus_fem_ma_h,sd_rectus_fem_ma_h,colors(1,:),0.5);
    hold on;
    niceBars(0:(numpts-1),m_semimem_ma_h,sd_semimem_ma_h,colors(2,:),0.5);  
    hold on;
    niceBars(0:(numpts-1),m_iliacus_ma_h,sd_iliacus_ma_h,colors(3,:),0.5);     
    hold on;
    niceBars(0:(numpts-1),m_glut_max2_ma_h,sd_glut_max2_ma_h,colors(4,:),0.5);  
    hold on;
    niceBars(0:(numpts-1),m_glut_med3_ma_h,sd_glut_med3_ma_h,colors(5,:),0.5);  
    hold on;    
    niceBars(0:(numpts-1),m_add_long_ma_h,sd_add_long_ma_h,colors(6,:),0.5);  
    hold on;    
    niceBars(0:(numpts-1),m_add_mag2_ma_h,sd_add_mag2_ma_h,colors(7,:),0.5);  
    axis tight;
    xlabel('Percent GC','fontsize',14);
    ylabel('Mom. Arms','fontsize',14);
    title('Hip Mom. Arms','fontsize',14);
    legend('RF','HAM','ILL','GMAX','GMED','ADDL','ADDM','location','eastoutside');        
    h_xlabel = get(gca,'XLabel');
    set(h_xlabel,'FontSize',14); 
    h_ylabel = get(gca,'YLabel');
    set(h_ylabel,'FontSize',14); 
    h_title = get(gca,'Title');
    set(h_title,'FontSize',14); 
    set(gca,'fontsize',14)
    set(gca,'linewidth',2)
  end;
end;

addpath ~/Desktop/export_fig
set(gcf,'Color',[1,1,1])
keyboard  % for resizing
export_fig lmtc_ma -png