% function [] = compare_exes(subjectID)
% Purpose:  Reads the set of motion files output by Darryl's executables
%           corresponding to subjectID and generates plots of the
%           gencoords vs time for comparing the output of the IK, REA, and 
%           CMC steps to the subject's experimental data
%
% Input:    subjectID is the prefix ('string') of the following input files, 
%           generated from the preprocessing step and Darryl's executables:
%               subjectID.mot
%               subjectIDik.mot
%               subjectIDrea.mot
%               subjectIDcmc.mot
%
% Called Functions:  read_motionfile.m
%                    
% ASA, 3-05


% Set flag for printing (1 = print to printer; 0 = print to screen only)
print_flag = 0;

% Set flag for pausing between figures (1 = pause, 0 = do not pause)
pause_flag = 1;

ic = 1.36;
ic2 = 2.55;
dur = 1.19;

% Read file subjectID.mot
% fname = strcat(subjectID, '_raw_all.mot');%changed file name from '.mot' to 'raw.mot'
% fname = strcat(subjectID, '_raw_presw2pk.mot');
% mot = read_motionfile('hpl_overground_slow_walk.trc');

% Read files subjectIDik.mot
% fname = strcat(subjectID, '_invkin.mot');
% fname = strcat(subjectID, '_invkin_presw2pk.mot');
% fname = strcat(subjectID, 'cmc_presw2pk_original.mot');
ik = read_motionfile2('MDeMers_IK_SlowWalk.mot');

% Read files subjectIDrea.mot
% fname = strcat(subjectID, '_rea.mot');
% fname = strcat(subjectID, '_rea_presw2pk.mot');
rea = read_motionfile2('MDeMers_slow_walk_RRA_Kinematics_q.mot');

% Read files subjectIDcmc.mot
% fname = strcat(subjectID, '_cmc.mot');
% fname = strcat(subjectID, '_cmc_presw2pk.mot');

cmc = read_motionfile2('MDeMers_slow_walk_cmc_SLS_Kinematics_q.mot');

% Generate plots
set(0, 'Units', 'pixels');
scnsize = get(0, 'ScreenSize');
scnwidth = scnsize(3);
scnheight = scnsize(4);
figpos_whole = [0.1*scnwidth, 0.1*scnheight, 0.8*scnwidth, 0.8*scnheight];
    

figure(1);   % Pelvis Translations and Rotations
    clf
    set(gcf, 'Position', figpos_whole, 'Color', 'w');
    set(gcf, 'PaperOrientation', 'landscape');
    set(gcf, 'PaperPosition', [1 1 9 6.5]);
    
    subplot(2, 3, 1);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'pelvis_tx'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'pelvis_tx'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'pelvis_tx'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'pelvis_tx'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = [' pelvis tx'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('anterior+ (m)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    hlegend = legend('{\itIK}', '{\itREA}', '{\itCMC}', 0);
    set(hlegend, 'Box', 'off', 'XColor', 'w', 'YColor', 'w');
        
    subplot(2, 3, 2);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'pelvis_ty'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'pelvis_ty'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'pelvis_ty'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'pelvis_ty'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = [ 'pelvis ty'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('superior+ (m)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0.6 1.2]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    
    subplot(2, 3, 3);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'pelvis_tz'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'pelvis_tz'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'pelvis_tz'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'pelvis_tz'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['pelvis tz'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('lateral R+ (m)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    if ik.data(1, cid_iky) < -0.5
        set(gca, 'Ylim', [-0.9 -0.6]);
    elseif ik.data(1, cid_iky) > 0.5
        set(gca, 'Ylim', [0.6 0.9]);
    else      
        set(gca, 'Ylim', [-0.15 0.15]);     
    end
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 4
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    
    subplot(2, 3, 4);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'pelvis_tilt'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'pelvis_tilt'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'pelvis_tilt'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'pelvis_tilt'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = [ 'pelvis tilt'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('posterior+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-20 15]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
            
    subplot(2, 3, 5);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'pelvis_list'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'pelvis_list'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'pelvis_list'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'pelvis_list'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = [ 'pelvis list'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('up L+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-10 15]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    
    subplot(2, 3, 6);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'pelvis_rotation'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'pelvis_rotation'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'pelvis_rotation'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'pelvis_rotation'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['pelvis rotation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('internal R+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-10 20]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    
    if pause_flag == 1
        pause;
    end

    
figure(2);   % Back Angles
    clf
    set(gcf, 'Position', figpos_whole, 'Color', 'w');
    set(gcf, 'PaperOrientation', 'landscape');
    set(gcf, 'PaperPosition', [1 1 9 6.5]);

    subplot(2, 3, 1);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'lumbar_extension'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'lumbar_extension'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'lumbar_extension'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'lumbar_extension'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['lumbar extension'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('extension+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-25 30]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
        
    subplot(2, 3, 2);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'lumbar_bending'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'lumbar_bending'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'lumbar_bending'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'lumbar_bending'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['lumbar bending'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('bending R+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-15 17]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    
    subplot(2, 3, 3);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'lumbar_rotation'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'lumbar_rotation'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'lumbar_rotation'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'lumbar_rotation'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['lumbar rotation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('internal R+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-20 15]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    hlegend = legend('{\itMOT}', '{\itIK}', '{\itREA}', '{\itCMC}', 0);
    set(hlegend, 'Box', 'off', 'XColor', 'w', 'YColor', 'w');

    if pause_flag == 1
        pause;
    end
    
    
figure(3);   % R Hip, Knee, Ankle Angles
    clf
    set(gcf, 'Position', figpos_whole, 'Color', 'w');
    set(gcf, 'PaperOrientation', 'landscape');
    set(gcf, 'PaperPosition', [1 1 9 6.5]);

    subplot(2, 3, 1);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'hip_flexion_r'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'hip_flexion_r'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'hip_flexion_r'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'hip_flexion_r'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['R hip flexion'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('flexion+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-40 40]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
            
    subplot(2, 3, 2);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'hip_adduction_r'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'hip_adduction_r'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'hip_adduction_r'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'hip_adduction_r'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['R hip adduction'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('adduction+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-15 15]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    
    subplot(2, 3, 3);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'hip_rotation_r'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'hip_rotation_r'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'hip_rotation_r'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'hip_rotation_r'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['R hip rotation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('internal+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-20 20]); 
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end

    subplot(2, 3, 4);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'knee_angle_r'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'knee_angle_r'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'knee_angle_r'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'knee_angle_r'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['R knee flexion'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('extension+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-70 5]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
            
    subplot(2, 3, 5);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'ankle_angle_r'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'ankle_angle_r'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'ankle_angle_r'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'ankle_angle_r'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['R ankle dorsiflexion'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('dorsiflexion+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-35 30]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    
    subplot(2, 3, 6);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'subtalar_angle_r'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'subtalar_angle_r'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'subtalar_angle_r'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'subtalar_angle_r'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['R subtalar angle'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('inversion+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-5 5]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 4
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    hlegend = legend('{\itMOT}', '{\itIK}', '{\itREA}', '{\itCMC}', 0);
    set(hlegend, 'Box', 'off', 'XColor', 'w', 'YColor', 'w');

    if pause_flag == 1
        pause;
    end

    
figure(4);   % L Hip, Knee, Ankle Angles
    clf
    set(gcf, 'Position', figpos_whole, 'Color', 'w');
    set(gcf, 'PaperOrientation', 'landscape');
    set(gcf, 'PaperPosition', [1 1 9 6.5]);

    subplot(2, 3, 1);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'hip_flexion_l'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'hip_flexion_l'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'hip_flexion_l'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'hip_flexion_l'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['L hip flexion'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('flexion+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-40 40]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
            
    subplot(2, 3, 2);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'hip_adduction_l'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'hip_adduction_l'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'hip_adduction_l'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'hip_adduction_l'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['L hip adduction'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('adduction+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-15 15]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    
    subplot(2, 3, 3);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'hip_rotation_l'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'hip_rotation_l'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'hip_rotation_l'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'hip_rotation_l'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['L hip rotation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('internal+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-20 20]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
   
    subplot(2, 3, 4);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'knee_angle_l'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'knee_angle_l'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'knee_angle_l'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'knee_angle_l'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['L knee flexion'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('extension+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-70 5]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
            
    subplot(2, 3, 5);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'ankle_angle_l'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'ankle_angle_l'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'ankle_angle_l'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'ankle_angle_l'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['L ankle dorsiflexion'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('dorsiflexion+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-35 30]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    
    subplot(2, 3, 6);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_moty = find(strcmpi(mot.labels, 'subtalar_angle_l'));
%     p = plot(mot.data(:, cid_motx), mot.data(:, cid_moty));
%     set(p, 'LineWidth', 1, 'Color', 'k');
%     hold on;
    cid_ikx = find(strcmpi(ik.labels, 'time'));
    cid_iky = find(strcmpi(ik.labels, 'subtalar_angle_l'));
    p = plot(ik.data(:, cid_ikx), ik.data(:, cid_iky));
    set(p, 'LineWidth', 1, 'LineStyle', ':', 'Color', [0.8 0.0 0.5]);
    hold on;
    cid_reax = find(strcmpi(rea.labels, 'time'));
    cid_reay = find(strcmpi(rea.labels, 'subtalar_angle_l'));
    p = plot(rea.data(:, cid_reax), rea.data(:, cid_reay));
    set(p, 'LineWidth', 1, 'LineStyle', '--', 'Color', [0.0 0.8 0.3]);
    hold on;
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'subtalar_angle_l'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1.5, 'Color', [0.0 0.0 0.8]);
    title_string = ['L subtalar angle'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('inversion+ (deg)', 'FontSize', 9, 'VerticalAlignment', 'bottom');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [-5 5]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 4
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    hlegend = legend('{\itMOT}', '{\itIK}', '{\itREA}', '{\itCMC}', 0);
    set(hlegend, 'Box', 'off', 'XColor', 'w', 'YColor', 'w');

    if pause_flag == 1
        pause;
    end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear cmc
cmc = read_motionfile3('MDeMers_slow_walk_cmc_SLS_controls.sto');

figure(5);   % R VAS, RF Excitations
    clf
    set(gcf, 'Position', figpos_whole, 'Color', 'w');
    set(gcf, 'PaperOrientation', 'landscape');
    set(gcf, 'PaperPosition', [1 1 9 6.5]);

    subplot(2, 3, 1);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'glut_med1_r.excitation'));
    p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['R VASmed Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')
    
    subplot(2, 3, 2);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'vas_int_r.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['R VASint Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')
%     subplot(2, 3, 3);
%     cid_cmcx = find(strcmpi(cmc.labels, 'time'));
%     cid_cmcy = find(strcmpi(cmc.labels, 'vas_lat_r_exc'));
%     p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
%     set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
%     title_string = [subjectID ':  R VASlat Excitation'];
%     title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
%     xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
% %     set(gca, 'Xtick', [0 0.2 0.4 0.8 1.0]);
%     set(gca, 'Ylim', [0 1]);
%     set(gca, 'Box', 'off', 'FontSize', 8);
%     ytickpositions = get(gca, 'Ytick');
%     if length(ytickpositions) > 5
%         new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
%         set(gca, 'Ytick', new_ytickpositions);
%     end
   
    subplot(2, 3, 4);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'rect_fem_r.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['R RF Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
           
    if pause_flag == 1
        pause;
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')
    
figure(6);   % R ILSPSO, GAS/SOL Excitations
    clf
    set(gcf, 'Position', figpos_whole, 'Color', 'w');
    set(gcf, 'PaperOrientation', 'landscape');
    set(gcf, 'PaperPosition', [1 1 9 6.5]);

    %subplot(2, 3, 1);
    %cid_cmcx = find(strcmpi(cmc.labels, 'time'));
%     cid_cmcy = find(strcmpi(cmc.labels, 'iliacus_r.excitation'));
%     p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
%     set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
%     title_string = ['R Iliacus Excitation'];
%     title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
%     xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
% %     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
%     set(gca, 'Ylim', [0 1]);
%     set(gca, 'Box', 'off', 'FontSize', 8);
%     ytickpositions = get(gca, 'Ytick');
%     if length(ytickpositions) > 5
%         new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
%         set(gca, 'Ytick', new_ytickpositions);
%     end
%     vline(2.025, 'k', 'RHS')
%     vline(2.175, 'k', 'LTO')
%     vline(2.65, 'k', 'LHS')
%     vline(2.775, 'k', 'RTO')  
%     
%     subplot(2, 3, 2);
%     cid_cmcx = find(strcmpi(cmc.labels, 'time'));
%     cid_cmcy = find(strcmpi(cmc.labels, 'psoas_r.excitation'));
%     p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
%     set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
%     title_string = ['R Psoas Excitation'];
%     title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
%     xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
% %     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
%     set(gca, 'Ylim', [0 1]);
%     set(gca, 'Box', 'off', 'FontSize', 8);
%     ytickpositions = get(gca, 'Ytick');
%     if length(ytickpositions) > 5
%         new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
%         set(gca, 'Ytick', new_ytickpositions);
%     end
%     vline(2.025, 'k', 'RHS')
%     vline(2.175, 'k', 'LTO')
%     vline(2.65, 'k', 'LHS')
%     vline(2.775, 'k', 'RTO')
    
    subplot(2, 3, 4);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'med_gas_r.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['R GASmed Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')
%     subplot(2, 3, 5);
%     cid_cmcx = find(strcmpi(cmc.labels, 'time'));
%     cid_cmcy = find(strcmpi(cmc.labels, 'lat_gas_r_exc'));
%     p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
%     set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
%     title_string = [subjectID ':  R GASlat Excitation'];
%     title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
%     xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
%     set(gca, 'Ylim', [0 1]);
%     set(gca, 'Box', 'off', 'FontSize', 8);
%     ytickpositions = get(gca, 'Ytick');
%     if length(ytickpositions) > 5
%         new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
%         set(gca, 'Ytick', new_ytickpositions);
%     end
    
    subplot(2, 3, 6);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'soleus_r.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['R Soleus Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
           
    if pause_flag == 1
        pause;
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')

figure(7);   % R Hamstrings, BFSH Excitations
    clf
    set(gcf, 'Position', figpos_whole, 'Color', 'w');
    set(gcf, 'PaperOrientation', 'landscape');
    set(gcf, 'PaperPosition', [1 1 9 6.5]);

%     subplot(2, 3, 1);
%     cid_cmcx = find(strcmpi(cmc.labels, 'time'));
%     cid_cmcy = find(strcmpi(cmc.labels, 'semimem_r_exc'));
%     p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
%     set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
%     title_string = [subjectID ':  R SM Excitation'];
%     title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
%     xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
%     set(gca, 'Ylim', [0 1]);
%     set(gca, 'Box', 'off', 'FontSize', 8);
%     ytickpositions = get(gca, 'Ytick');
%     if length(ytickpositions) > 5
%         new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
%         set(gca, 'Ytick', new_ytickpositions);
%     end
            
%     subplot(2, 3, 2);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_cmcx = find(strcmpi(cmc.labels, 'time'));
%     cid_cmcy = find(strcmpi(cmc.labels, 'semiten_r_exc'));
%     p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
%     set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
%     title_string = [subjectID ':  R ST Excitation'];
%     title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
%     xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
%     set(gca, 'Ylim', [0 1]);
%     set(gca, 'Box', 'off', 'FontSize', 8);
%     ytickpositions = get(gca, 'Ytick');
%     if length(ytickpositions) > 5
%         new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
%         set(gca, 'Ytick', new_ytickpositions);
%     end
    
    subplot(2, 3, 3);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'bifemlh_r.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['R BFLH Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')
    
    subplot(2, 3, 4);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'bifemsh_r.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['R BFSH Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')
    
    subplot(2, 3, 5); %R TA
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'tib_ant_r.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['R Tib Ant Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end

           
    if pause_flag == 1
        pause;
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')
    
figure(8);   % L VAS, RF Excitations
    clf
    set(gcf, 'Position', figpos_whole, 'Color', 'w');
    set(gcf, 'PaperOrientation', 'landscape');
    set(gcf, 'PaperPosition', [1 1 9 6.5]);

%     subplot(2, 3, 1);
%     cid_cmcx = find(strcmpi(cmc.labels, 'time'));
%     cid_cmcy = find(strcmpi(cmc.labels, 'vas_med_r_exc'));
%     p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
%     set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
%     title_string = ['R VASmed Excitation'];
%     title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
%     xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
% %     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
%     set(gca, 'Ylim', [0 1]);
%     set(gca, 'Box', 'off', 'FontSize', 8);
%     ytickpositions = get(gca, 'Ytick');
%     if length(ytickpositions) > 5
%         new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
%         set(gca, 'Ytick', new_ytickpositions);
%     end
            
    subplot(2, 3, 2);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'vas_int_l.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['L VASint Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')
%     subplot(2, 3, 3);
%     cid_cmcx = find(strcmpi(cmc.labels, 'time'));
%     cid_cmcy = find(strcmpi(cmc.labels, 'vas_lat_r_exc'));
%     p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
%     set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
%     title_string = [subjectID ':  R VASlat Excitation'];
%     title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
%     xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
% %     set(gca, 'Xtick', [0 0.2 0.4 0.8 1.0]);
%     set(gca, 'Ylim', [0 1]);
%     set(gca, 'Box', 'off', 'FontSize', 8);
%     ytickpositions = get(gca, 'Ytick');
%     if length(ytickpositions) > 5
%         new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
%         set(gca, 'Ytick', new_ytickpositions);
%     end
   
    subplot(2, 3, 4);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'rect_fem_l.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['L RF Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
           
    if pause_flag == 1
        pause;
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')

    
figure(9);   % L ILSPSO, GAS/SOL Excitations
     clf
    set(gcf, 'Position', figpos_whole, 'Color', 'w');
    set(gcf, 'PaperOrientation', 'landscape');
    set(gcf, 'PaperPosition', [1 1 9 6.5]);

    subplot(2, 3, 1);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'iliacus_l.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['L Iliacus Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')  
    
    subplot(2, 3, 2);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'psoas_l.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['L Psoas Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')
    
    subplot(2, 3, 4);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'med_gas_l.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['L GASmed Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')
    
%     subplot(2, 3, 5);
%     cid_cmcx = find(strcmpi(cmc.labels, 'time'));
%     cid_cmcy = find(strcmpi(cmc.labels, 'lat_gas_r_exc'));
%     p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
%     set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
%     title_string = [subjectID ':  R GASlat Excitation'];
%     title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
%     xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
%     set(gca, 'Ylim', [0 1]);
%     set(gca, 'Box', 'off', 'FontSize', 8);
%     ytickpositions = get(gca, 'Ytick');
%     if length(ytickpositions) > 5
%         new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
%         set(gca, 'Ytick', new_ytickpositions);
%     end
    
    subplot(2, 3, 6);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'soleus_l.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['L Soleus Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
           
    if pause_flag == 1
        pause;
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')


figure(10);   % L Hamstrings, BFSH Excitations
    clf
    set(gcf, 'Position', figpos_whole, 'Color', 'w');
    set(gcf, 'PaperOrientation', 'landscape');
    set(gcf, 'PaperPosition', [1 1 9 6.5]);

%     subplot(2, 3, 1);
%     cid_cmcx = find(strcmpi(cmc.labels, 'time'));
%     cid_cmcy = find(strcmpi(cmc.labels, 'semimem_r_exc'));
%     p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
%     set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
%     title_string = [subjectID ':  R SM Excitation'];
%     title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
%     xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
%     set(gca, 'Ylim', [0 1]);
%     set(gca, 'Box', 'off', 'FontSize', 8);
%     ytickpositions = get(gca, 'Ytick');
%     if length(ytickpositions) > 5
%         new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
%         set(gca, 'Ytick', new_ytickpositions);
%     end
            
%     subplot(2, 3, 2);
%     cid_motx = find(strcmpi(mot.labels, 'time'));
%     cid_cmcx = find(strcmpi(cmc.labels, 'time'));
%     cid_cmcy = find(strcmpi(cmc.labels, 'semiten_r_exc'));
%     p = plot(cmc.data(:, cid_cmcx), cmc.data(:, cid_cmcy));
%     set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
%     title_string = [subjectID ':  R ST Excitation'];
%     title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
%     xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
%     set(gca, 'Ylim', [0 1]);
%     set(gca, 'Box', 'off', 'FontSize', 8);
%     ytickpositions = get(gca, 'Ytick');
%     if length(ytickpositions) > 5
%         new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
%         set(gca, 'Ytick', new_ytickpositions);
%     end
    
    subplot(2, 3, 3);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'bifemlh_l.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['L BFLH Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')
    
    subplot(2, 3, 4);
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'bifemsh_l.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['L BFSH Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')
    
    subplot(2, 3, 5); %L TA
    cid_cmcx = find(strcmpi(cmc.labels, 'time'));
    cid_cmcy = find(strcmpi(cmc.labels, 'tib_ant_l.excitation'));
    p = plot((cmc.data(:, cid_cmcx)), cmc.data(:, cid_cmcy));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.0 0.8]);
    title_string = ['L Tib Ant Excitation'];
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
%     set(gca, 'Xtick', [0 0.2 0.4 0.6 0.8 1.0]);
    set(gca, 'Ylim', [0 1]);
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    vline(2.025, 'k', 'RHS')
    vline(2.175, 'k', 'LTO')
    vline(2.65, 'k', 'LHS')
    vline(2.775, 'k', 'RTO')
           
    if pause_flag == 1
        pause;
    end
    
if print_flag == 1    
    print -f1;
    print -f2;
    print -f3;
    print -f4;
    print -f5;
    print -f6;
    print -f7;
    print -f8;
    print -f9;
    print -f10;
end

    
    
