%%% Plot OpenSim result, Muscle excitation
%%% Ming Xiao 03/07/07

clear all;
close all;

inmotfile = 'subject01_walk1_controls.sto'; %input('Which motion file: ');
rowstoread = 4299+5;

row = rowstoread - 5;

% Read mot file and remove header
j=1;
fid=fopen(inmotfile);
for i=1:rowstoread
    tline = fgetl(fid);
    %disp(tline)
    if i>5
        row_i=str2num(tline);
        if ~isempty(row_i);
            data2(j,:) = row_i;
            j=j+1;
        end;
    end;
end
fclose(fid);

% gc = [100/row:100/row:100];

j =1;
for i =1:round(row/10)
    data(i,:) = data2(j,:);
    j = j +10;
end


figure
subplot(2,2,1);
plot(data(:,2),'r','LineWidth',2);
hold on
plot(data(:,3),'r--','LineWidth',2);
plot(data(:,4),'b-.','LineWidth',2);
legend('GMED1','GMED2','GMED3');
% axis([0 100 0 1]);
% xlabel('% gait cycle');

subplot(2,2,2);
plot(data(:,5),'r','LineWidth',2);
hold on
plot(data(:,6),'r--','LineWidth',2);
plot(data(:,20),'b','LineWidth',2);
plot(data(:,21),'b--','LineWidth',2);
legend('HAMSTRING','BFSH','RF','VAS');
% axis([0 100 0 1]);
% xlabel('% gait cycle');


subplot(2,2,3);
plot(data(:,12),'r','LineWidth',2);
hold on
plot(data(:,13),'r--','LineWidth',2);
plot(data(:,14),'b-.','LineWidth',2);
legend('GMAX1','GMAX2','GMAX3');
% axis([0 100 0 1]);
% xlabel('% gait cycle');


subplot(2,2,4);
plot(data(:,22),'r','LineWidth',2);
hold on
plot(data(:,23),'r--','LineWidth',2);
plot(data(:,25),'b-.','LineWidth',2);
legend('MGAS','SOL','TA');
% axis([0 100 0 1]);
% xlabel('% gait cycle');