

%load data
%data = csvread('file name',1,0);
% assign variables from 'data'
Lsteplength = data(:,40);
ix = (Lsteplength==0); Lsteplength(ix) = [];
Lstridetime = data(:,43);
ix = (Lstridetime==0); Lstridetime(ix) = [];
Lstancetime = data(:,39);
ix = (Lstancetime==0); Lstancetime(ix) = [];
Lswingtime = data(:,44);
ix = (Lswingtime==0); Lswingtime(ix) = [];
Rsteplength = data(:,251);
ix = (Rsteplength==0); Rsteplength(ix) = [];
Rstridetime = data(:,254);
ix = (Rstridetime==0); Rstridetime(ix) = [];
Rstancetime = data(:,250);
ix = (Rstancetime==0); Rstancetime(ix) = [];
Rswingtime = data(:,255);
ix = (Rswingtime==0); Rswingtime(ix) = [];
walksp = data(:,285);
RotPelvicObl = data(:,268);
RotPelvicRot = data(:,269);
RotPelvicTil = data(:,270);
LHipFlex = data(:,263);
LHipAbAd = data(:,262);
LHipRot = data(:,264);
RHipFlex = data(:,276);
RHipAbAd = data(:,275);
RHipRot = data(:,277);
LKneeFlex = data(:,266);
LKneeAbAd = data(:,265);
LKneeRot = data(:,267);
RKneeFlex = data(:,279);
RKneeAbAd = data(:,278);
RKneeRot = data(:,280);
LAnkleFlex = data(:,259);
LankleProSup = data(:,260);
RAnkleFlex = data(:,272);
RAnkleProSup = data(:,273);
LFootProg = data(:,45);
RFootProg = data(:,256);

MomentLHipAbAd = data(:,201);
MomentLHipFlex = data(:,202);
MomentLHipRot = data(:,203);
MomentRHipAbAd = data(:,214);
MomentRHipFlex = data(:,215);
MomentRHipRot = data(:,216);
MomentLKneeAbAd = data(:,204);
MomentLKneeFlex = data(:,205);
MomentLKneeRot = data(:,206);
MomentRKneeAbAd = data(:,217);
MomentRKneeFlex = data(:,218);
MomentRKneeRot = data(:,219);
MomentLAnkleFlex = data(:,198);
MomentRAnkleFlex = data(:,211);
% data has zeros to remove. Removed

%%%%% MOMENTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% HIP FLEX
[pksMntLHipFlex locsMntLHipFlex] = findpeaks(MomentLHipFlex,'minpeakdistance',30,'minpeakheight',0.1); % may need to adjust threshold
AVE_Peak_LHipFlexMoment = mean(pksMntLHipFlex);
SDLHipFlexMoment = std(pksMntLHipFlex);
% these are positive peaks
MomentLHipFlexInv = MomentLHipFlex*-1;
[pksMntLHipFlexInv locsMntLHipFlexInv] = findpeaks(MomentLHipFlexInv,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_LHipFlexMomentInv = mean(pksMntLHipFlexInv);
SDLHipFlexMomentInv = std(pksMntLHipFlexInv);
%these are negative peaks 
% FOR LEFT HIP FLEXION - INV PEAK IS NEEDED. 

[pksMntRHipFlex locsMntRHipFlex] = findpeaks(MomentRHipFlex,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_RHipFlexMoment = mean(pksMntRHipFlex);
SDRHipFlexMoment = std(pksMntRHipFlex);
% these are positive peaks
MomentRHipFlexInv = MomentRHipFlex*-1;
[pksMntRHipFlexInv locsMntRHipFlexInv] = findpeaks(MomentRHipFlexInv,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_RHipFlexMomentInv = mean(pksMntRHipFlexInv);
SDRHipFlexMomentInv = std(pksMntRHipFlexInv);
% FOR LEFT HIP FLEXION - POS PEAK IS NEEDED. 

% HIP ABAD
[pksMntLHipAbAd locsMntLHipAbAd] = findpeaks(MomentLHipAbAd,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_LHipAbAdMoment = mean(pksMntLHipAbAd);
SDLHipAbAdMoment = std(pksMntLHipAbAd);
% these are positive peaks

MomentLHipAbAdInv = MomentLHipAbAd*-1;
[pksMntLHipAbAdInv locsMntLHipAbAdInv] = findpeaks(MomentLHipAbAdInv,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_LHipAbAdMomentInv = mean(pksMntLHipAbAdInv);
SDLHipAbAdMomentInv = std(pksMntLHipAbAdInv);
%these are negative peaks 

[pksMntRHipAbAd locsMntRHipAbAd] = findpeaks(MomentRHipAbAd,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_RHipAbAdMoment = mean(pksMntRHipAbAd);
SDRHipAbAdMoment = std(pksMntRHipAbAd);
% these are positive peaks
MomentRHipAbAdInv = MomentRHipAbAd*-1;
[pksMntRHipAbAdInv locsMntRHipAbAdInv] = findpeaks(MomentRHipAbAdInv,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_RHipAbAdMomentInv = mean(pksMntRHipAbAdInv);
SDRHipAbAdMomentInv = std(pksMntRHipAbAdInv);

% HIP ROT
[pksMntLHipRot locsMntLHipRot] = findpeaks(MomentLHipRot,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_LHipRotMoment = mean(pksMntLHipRot);
SDLHipRotMoment = std(pksMntLHipRot);
% these are positive peaks

MomentLHipRotInv = MomentLHipRot*-1;
[pksMntLHipRotInv locsMntLHipRotInv] = findpeaks(MomentLHipRotInv,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_LHipRotMomentInv = mean(pksMntLHipRotInv);
SDLHipRotMomentInv = std(pksMntLHipRotInv);
%these are negative peaks 

[pksMntRHipRot locsMntRHipRot] = findpeaks(MomentRHipRot,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_RHipRotMoment = mean(pksMntRHipRot);
SDRHipRotMoment = std(pksMntRHipRot);
% these are positive peaks
MomentRHipRotInv = MomentRHipRot*-1;
[pksMntRHipRotInv locsMntRHipRotInv] = findpeaks(MomentRHipRotInv,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_RHipRotMomentInv = mean(pksMntRHipRotInv);
SDRHipRotMomentInv = std(pksMntRHipRotInv);

% KNEE FLEX
[pksMntLKneeFlex locsMntLKneeFlex] = findpeaks(MomentLKneeFlex,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_LKneeFlexMoment = mean(pksMntLKneeFlex);
SDLKneeFlexMoment = std(pksMntLKneeFlex);
% these are positive peaks
MomentLKneeFlexInv = MomentLKneeFlex*-1;
[pksMntLKneeFlexInv locsMntLKneeFlexInv] = findpeaks(MomentLKneeFlexInv,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_LKneeFlexMomentInv = mean(pksMntLKneeFlexInv);
SDLKneeFlexMomentInv = std(pksMntLKneeFlexInv);
%these are negative peaks. 

[pksMntRKneeFlex locsMntRKneeFlex] = findpeaks(MomentRKneeFlex,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_RKneeFlexMoment = mean(pksMntRKneeFlex);
SDRKneeFlexMoment = std(pksMntRKneeFlex);
% these are positive peaks
MomentRKneeFlexInv = MomentRKneeFlex*-1;
[pksMntRKneeFlexInv locsMntRKneeFlexInv] = findpeaks(MomentRKneeFlexInv,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_RKneeFlexMomentInv = mean(pksMntRKneeFlexInv);
SDRKneeFlexMomentInv = std(pksMntRKneeFlexInv);
% these are negative peaks

% KNEE ABAD
[pksMntLKneeAbAd locsMntLKneeAbAd] = findpeaks(MomentLKneeAbAd,'minpeakdistance',20,'minpeakheight',0.1);
AVE_Peak_LKneeAbAdMoment = mean(pksMntLKneeAbAd);
SDLKneeAbAdMoment = std(pksMntLKneeAbAd);
% these are positive peaks

MomentLKneeAbAdInv = MomentLKneeAbAd*-1;
[pksMntLKneeAbAdInv locsMntLKneeAbAdInv] = findpeaks(MomentLKneeAbAdInv,'minpeakdistance',20,'minpeakheight',0.01);
AVE_Peak_LKneeAbAdMomentInv = mean(pksMntLKneeAbAdInv);
SDLKneeAbAdMomentInv = std(pksMntLKneeAbAdInv);
these are negative peaks. 

[pksMntRKneeAbAd locsMntRKneeAbAd] = findpeaks(MomentRKneeAbAd,'minpeakdistance',20,'minpeakheight',0.1);
AVE_Peak_RKneeAbAdMoment = mean(pksMntRKneeAbAd);
SDRKneeAbAdMoment = std(pksMntRKneeAbAd);
these are positive peaks
MomentRKneeAbAdInv = MomentRKneeAbAd*-1;
[pksMntRKneeAbAdInv locsMntRKneeAbAdInv] = findpeaks(MomentRKneeAbAdInv,'minpeakdistance',20,'minpeakheight',0.1);
AVE_Peak_RKneeAbAdMomentInv = mean(pksMntRKneeAbAdInv);
SDRKneeAbAdMomentInv = std(pksMntRKneeAbAdInv);
%these are negative peaks. 

% KNEE Rot
[pksMntLKneeRot locsMntLKneeRot] = findpeaks(MomentLKneeRot,'minpeakdistance',30,'minpeakheight',0.01);
AVE_Peak_LKneeRotMoment = mean(pksMntLKneeRot);
SDLKneeRotMoment = std(pksMntLKneeRot);
% these are positive peaks
MomentLKneeRotInv = MomentLKneeRot*-1;
[pksMntLKneeRotInv locsMntLKneeRotInv] = findpeaks(MomentLKneeRotInv,'minpeakdistance',30,'minpeakheight',0.01);
AVE_Peak_LKneeRotMomentInv = mean(pksMntLKneeRotInv);
SDLKneeRotMomentInv = std(pksMntLKneeRotInv);
%these are negative peaks. 

[pksMntRKneeRot locsMntRKneeRot] = findpeaks(MomentRKneeRot,'minpeakdistance',30,'minpeakheight',0.01);
AVE_Peak_RKneeRotMoment = mean(pksMntRKneeRot);
SDRKneeRotMoment = std(pksMntRKneeRot);
% these are positive peaks
MomentRKneeRotInv = MomentRKneeRot*-1;
[pksMntRKneeRotInv locsMntRKneeRotInv] = findpeaks(MomentRKneeRotInv,'minpeakdistance',30,'minpeakheight',0.01);
AVE_Peak_RKneeRotMomentInv = mean(pksMntRKneeRotInv);
SDRKneeRotMomentInv = std(pksMntRKneeRotInv);
%these are negative peaks. 


% ANKLE FLEX
[pksMntRAnkleFlex locsMntRAnkleFlex] = findpeaks(MomentRAnkleFlex,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_RAnkleFlexMoment = mean(pksMntRAnkleFlex);
SDRAnkleFlexMoment = std(pksMntRAnkleFlex);
% these are positive peaks ANKLE IS POSITIVE PEAKS ONLY.
MomentRAnkleFlexInv = MomentRAnkleFlex*-1;
[pksMntRAnkleFlexInv locsMntRAnkleFlexInv] = findpeaks(MomentRAnkleFlexInv,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_RAnkleFlexMomentInv = mean(pksMntRAnkleFlexInv);
SDRAnkleFlexMomentInv = std(pksMntRAnkleFlexInv);
% these are negative peaks

[pksMntLAnkleFlex locsMntLAnkleFlex] = findpeaks(MomentLAnkleFlex,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_LAnkleFlexMoment = mean(pksMntLAnkleFlex);
SDLAnkleFlexMoment = std(pksMntLAnkleFlex);
% these are positive peaks ANKLE IS POSTIVE PEAKS ONLY.
MomentLAnkleFlexInv = MomentLAnkleFlex*-1;
[pksMntLAnkleFlexInv locsMntLAnkleFlexInv] = findpeaks(MomentLAnkleFlexInv,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_LAnkleFlexMomentInv = mean(pksMntLAnkleFlexInv);
SDLAnkleFlexMomentInv = std(pksMntLAnkleFlexInv);
% these are negative peaks

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% SPATIOTEMPORAL %%%%%%%%%%%%%%%%%

samp = 1:length(data)-50;

AVEwalksp = mean(walksp);
SDwalksp = std(walksp);
AVELsteplength = mean(Lsteplength);
SDLsteplength = std(Lsteplength);
AVERsteplength = mean(Rsteplength);
SDRsteplength = std(Rsteplength);

AVELstridetime = mean(Lstridetime);
SDLstridetime = std(Lstridetime);
AVERstridetime = mean(Rstridetime);
SDRstridetime = std(Rstridetime);

AVELstancetime = mean(Lstancetime);
SDLstancetime = std(Lstancetime);
AVERstancetime = mean(Rstancetime);
SDRstancetime = std(Rstancetime);

AVELswingtime = mean(Lswingtime);
SDLswingtime = std(Lswingtime);
AVERswingtime = mean(Rswingtime);
SDRswingtime = std(Rswingtime);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Kinematics %%%%

% PELVIS
[pksRotPelvicObl locsRotPelvicObl] = findpeaks(RotPelvicObl,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_RotPelvicObl = mean(pksRotPelvicObl);
SDRotPelvicObl = std(pksRotPelvicObl);
% these are positive peaks
RotPelvicOblInv = RotPelvicObl*-1;
[pksRotPelvicOblInv locsRotPelvicOblInv] = findpeaks(RotPelvicOblInv,'minpeakdistance',30,'minpeakheight',2);
AVE_Peak_RotPelvicOblInv = mean(pksRotPelvicOblInv);
SDRotPelvicOblInv = std(pksRotPelvicOblInv);

[pksRotPelvicRot locsRotPelvicRot] = findpeaks(RotPelvicRot,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_RotPelvicRot = mean(pksRotPelvicRot);
SDRotPelvicRot = std(pksRotPelvicRot);
% these are positive peaks
RotPelvicRotInv = RotPelvicRot*-1;
[pksRotPelvicRotInv locsRotPelvicRotInv] = findpeaks(RotPelvicRotInv,'minpeakdistance',30,'minpeakheight',2);
AVE_Peak_RotPelvicRotInv = mean(pksRotPelvicRotInv);
SDRotPelvicRotInv = std(pksRotPelvicRotInv);

[pksRotPelvicTil locsRotPelvicTil] = findpeaks(RotPelvicTil,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_RotPelvicTil = mean(pksRotPelvicTil);
SDRotPelvicTil = std(pksRotPelvicTil);
% these are positive peaks
RotPelvicTilInv = RotPelvicTil*-1;
[pksRotPelvicTilInv locsRotPelvicTilInv] = findpeaks(RotPelvicTilInv,'minpeakdistance',30,'minpeakheight',2);
AVE_Peak_RotPelvicTilInv = mean(pksRotPelvicTilInv);
SDRotPelvicTilInv = std(pksRotPelvicTilInv);

% HIP FLEX
[pksLHipFlex locsLHipFlex] = findpeaks(LHipFlex,'minpeakdistance',30,'minpeakheight',2);
AVE_Peak_LHipFlex = mean(pksLHipFlex);
SDLHipFlex = std(pksLHipFlex);
% these are positive peaks
LHipFlexInv = LHipFlex*-1;
[pksLHipFlexInv locsLHipFlexInv] = findpeaks(LHipFlexInv,'minpeakdistance',30,'minpeakheight',2);
AVE_Peak_LHipFlexInv = mean(pksLHipFlexInv);
SDLHipFlexInv = std(pksLHipFlexInv);
%these are negative peaks 

[pksRHipFlex locsRHipFlex] = findpeaks(RHipFlex,'minpeakdistance',30,'minpeakheight',2);
AVE_Peak_RHipFlex = mean(pksRHipFlex);
SDRHipFlex = std(pksRHipFlex);
% these are positive peaks
RHipFlexInv = RHipFlex*-1;
[pksRHipFlexInv locsRHipFlexInv] = findpeaks(RHipFlexInv,'minpeakdistance',30,'minpeakheight',2);
AVE_Peak_RHipFlexInv = mean(pksRHipFlexInv);
SDRHipFlexInv = std(pksRHipFlexInv);
%these are negative peaks 

% HIP ABAD
[pksLHipAbAd locsLHipAbAd] = findpeaks(LHipAbAd,'minpeakdistance',30,'minpeakheight',2);
AVE_Peak_LHipAbAd = mean(pksLHipAbAd);
SDLHipAbAd = std(pksLHipAbAd);
% these are positive peaks

LHipAbAdInv = LHipAbAd*-1;
[pksLHipAbAdInv locsLHipAbAdInv] = findpeaks(LHipAbAdInv,'minpeakdistance',30,'minpeakheight',2);
AVE_Peak_LHipAbAdInv = mean(pksLHipAbAdInv);
SDLHipAbAdInv = std(pksLHipAbAdInv);
%these are negative peaks 

[pksRHipAbAd locsRHipAbAd] = findpeaks(RHipAbAd,'minpeakdistance',30,'minpeakheight',2);
AVE_Peak_RHipAbAd = mean(pksRHipAbAd);
SDRHipAbAd = std(pksRHipAbAd);
% these are positive peaks
RHipAbAdInv = RHipAbAd*-1;
[pksRHipAbAdInv locsRHipAbAdInv] = findpeaks(RHipAbAdInv,'minpeakdistance',30,'minpeakheight',2);
AVE_Peak_RHipAbAdInv = mean(pksRHipAbAdInv);
SDRHipAbAdInv = std(pksRHipAbAdInv);

% HIP ROT
[pksLHipRot locsLHipRot] = findpeaks(LHipRot,'minpeakdistance',30,'minpeakheight',1);
AVE_Peak_LHipRot = mean(pksLHipRot);
SDLHipRot = std(pksLHipRot);
% these are positive peaks

LHipRotInv = LHipRot*-1;
[pksLHipRotInv locsLHipRotInv] = findpeaks(LHipRotInv,'minpeakdistance',30,'minpeakheight',1);
AVE_Peak_LHipRotInv = mean(pksLHipRotInv);
SDLHipRotInv = std(pksLHipRotInv);
%these are negative peaks 

[pksRHipRot locsRHipRot] = findpeaks(RHipRot,'minpeakdistance',30,'minpeakheight',1);
AVE_Peak_RHipRot = mean(pksRHipRot);
SDRHipRot = std(pksRHipRot);
% these are positive peaks
RHipRotInv = RHipRot*-1;
[pksRHipRotInv locsRHipRotInv] = findpeaks(RHipRotInv,'minpeakdistance',30,'minpeakheight',1);
AVE_Peak_RHipRotInv = mean(pksRHipRotInv);
SDRHipRotInv = std(pksRHipRotInv);

% KNEE FLEX
[pksLKneeFlex locsLKneeFlex] = findpeaks(LKneeFlex,'minpeakdistance',30,'minpeakheight',10);
AVE_Peak_LKneeFlex = mean(pksLKneeFlex);
SDLKneeFlex = std(pksLKneeFlex);
% these are positive peaks
LKneeFlexInv = LKneeFlex*-1;
[pksLKneeFlexInv locsLKneeFlexInv] = findpeaks(LKneeFlexInv,'minpeakdistance',30,'minpeakheight',0.1);
AVE_Peak_LKneeFlexInv = mean(pksLKneeFlexInv);
SDLKneeFlexInv = std(pksLKneeFlexInv);
%these are negative peaks. 

[pksRKneeFlex locsRKneeFlex] = findpeaks(RKneeFlex,'minpeakdistance',30,'minpeakheight',10);
AVE_Peak_RKneeFlex = mean(pksRKneeFlex);
SDRKneeFlex = std(pksRKneeFlex);
% these are positive peaks
RKneeFlexInv = RKneeFlex*-1;
[pksRKneeFlexInv locsRKneeFlexInv] = findpeaks(RKneeFlexInv,'minpeakdistance',30,'minpeakheight',-10);
AVE_Peak_RKneeFlexInv = mean(pksRKneeFlexInv);
SDRKneeFlexInv = std(pksRKneeFlexInv);
% these are negative peaks


% ANKLE FLEX
[pksRAnkleFlex locsRAnkleFlex] = findpeaks(RAnkleFlex,'minpeakdistance',30,'minpeakheight',5);
AVE_Peak_RAnkleFlex = mean(pksRAnkleFlex);
SDRAnkleFlex = std(pksRAnkleFlex);
% these are positive peaks ANKLE IS POSTIVE PEAKS ONLY.
RAnkleFlexInv = RAnkleFlex*-1;
[pksRAnkleFlexInv locsRAnkleFlexInv] = findpeaks(RAnkleFlexInv,'minpeakdistance',30,'minpeakheight',10);
AVE_Peak_RAnkleFlexInv = mean(pksRAnkleFlexInv);
SDRAnkleFlexInv = std(pksRAnkleFlexInv);
% these are negative peaks

[pksLAnkleFlex locsLAnkleFlex] = findpeaks(LAnkleFlex,'minpeakdistance',30,'minpeakheight',5);
AVE_Peak_LAnkleFlex = mean(pksLAnkleFlex);
SDLAnkleFlex = std(pksLAnkleFlex);
% these are positive peaks ANKLE IS POSTIVE PEAKS ONLY.
LAnkleFlexInv = LAnkleFlex*-1;
[pksLAnkleFlexInv locsLAnkleFlexInv] = findpeaks(LAnkleFlexInv,'minpeakdistance',30,'minpeakheight',10);
AVE_Peak_LAnkleFlexInv = mean(pksLAnkleFlexInv);
SDLAnkleFlexInv = std(pksLAnkleFlexInv);
% these are negative peaks
    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5    

%%%% PerStep data %%%%%%%%%%%%%%%%%%

forceVert = data(:,10);
NWB = find(forceVert ==0);
ixfirstHealStrike = NWB(1);
NWBdiff = diff(NWB);
NWBx = find(NWBdiff ~=1);% these are the indicies
%NWBxis the index of NWB for heal strike.

for n=1:length(NWBx)
    healstrikeix(n) = NWB(NWBx(n));
end
% healstrikeix is now the index of the heal strikes
healstrikeixdiff = diff(healstrikeix);

len = length(healstrikeix)-1;
for n=1:len
    FvertStride(1:(healstrikeixdiff(n)+1),n) = forceVert(healstrikeix(n):healstrikeix(n+1));
end

% seperate out  data per stride. 
for n=1:len
    MomLHipFStride(1:(healstrikeixdiff(n)+1),n) = MomentLHipFlex(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    MomRHipFStride(1:(healstrikeixdiff(n)+1),n) = MomentRHipFlex(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    MomLHipAbAdStride(1:(healstrikeixdiff(n)+1),n) = MomentLHipAbAd(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    MomRHipAbAdStride(1:(healstrikeixdiff(n)+1),n) = MomentRHipAbAd(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    MomLHipRotStride(1:(healstrikeixdiff(n)+1),n) = MomentLHipRot(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    MomRHipRotStride(1:(healstrikeixdiff(n)+1),n) = MomentRHipRot(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    MomLKneeFStride(1:(healstrikeixdiff(n)+1),n) = MomentLKneeFlex(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    MomRKneeFStride(1:(healstrikeixdiff(n)+1),n) = MomentRKneeFlex(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    MomLKneeAbAdStride(1:(healstrikeixdiff(n)+1),n) = MomentLKneeAbAd(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    MomRKneeAbAdStride(1:(healstrikeixdiff(n)+1),n) = MomentRKneeAbAd(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    MomLAnkleFStride(1:(healstrikeixdiff(n)+1),n) = MomentLAnkleFlex(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    MomRAnkleFStride(1:(healstrikeixdiff(n)+1),n) = MomentRAnkleFlex(healstrikeix(n):healstrikeix(n+1));
end

%Kinematics

% seperate out  data per stride. 
for n=1:len
    LHipFStride(1:(healstrikeixdiff(n)+1),n) = LHipFlex(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    RHipFStride(1:(healstrikeixdiff(n)+1),n) = RHipFlex(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    LHipAbAdStride(1:(healstrikeixdiff(n)+1),n) = LHipAbAd(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    RHipAbAdStride(1:(healstrikeixdiff(n)+1),n) = RHipAbAd(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    LHipRotStride(1:(healstrikeixdiff(n)+1),n) = LHipRot(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    RHipRotStride(1:(healstrikeixdiff(n)+1),n) = RHipRot(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    LKneeFStride(1:(healstrikeixdiff(n)+1),n) = LKneeFlex(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    RKneeFStride(1:(healstrikeixdiff(n)+1),n) = RKneeFlex(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    LKneeAbAdStride(1:(healstrikeixdiff(n)+1),n) = LKneeAbAd(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    RKneeAbAdStride(1:(healstrikeixdiff(n)+1),n) = RKneeAbAd(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    LAnkleFStride(1:(healstrikeixdiff(n)+1),n) = LAnkleFlex(healstrikeix(n):healstrikeix(n+1));
end

for n=1:len
    RAnkleFStride(1:(healstrikeixdiff(n)+1),n) = RAnkleFlex(healstrikeix(n):healstrikeix(n+1));
end


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% time normalise to 100 points using linear interpolation

if 0

x = LHipFStride;
TimeNormLinearInterpol
LHipFStrideTimeNorm = y;
clear x;
clear y;

x = RHipFStride;
TimeNormLinearInterpol
RHipFStrideTimeNorm = y;
clear x;
clear y;

x = LKneeFStride;
TimeNormLinearInterpol
LKneeFStrideTimeNorm = y;
clear x;
clear y;

x = RKneeFStride;
TimeNormLinearInterpol
RKneeFStrideTimeNorm = y;
clear x;
clear y;

%%%%%%%%%%%%%%%%%%%%%%%%%%


A = LHipFStrideTimeNorm;
[r, meanA, uA, lA] = cmc(A);
LHipFStrideTimeNorm_CurveMean = meanA;
LHipFStrideTimeNorm_U95CI = uA;
LHipFStrideTimeNorm_L95CI = lA;
LHipFStrideTimeNorm_CMC = r;
clear r;
clear meanA;
clear uA;
clear lA
clear A;

A = RHipFStrideTimeNorm;
[r, meanA, uA, lA] = cmc(A);
RHipFStrideTimeNorm_CurveMean = meanA;
RHipFStrideTimeNorm_U95CI = uA;
RHipFStrideTimeNorm_L95CI = lA;
RHipFStrideTimeNorm_CMC = r;
clear r;
clear meanA;
clear uA;
clear lA
clear A;

A = LKneeFStrideTimeNorm;
[r, meanA, uA, lA] = cmc(A);
LKneeFStrideTimeNorm_CurveMean = meanA;
LKneeFStrideTimeNorm_U95CI = uA;
LKneeFStrideTimeNorm_L95CI = lA;
LKneeFStrideTimeNorm_CMC = r;
clear r;
clear meanA;
clear uA;
clear lA
clear A;

A = RKneeFStrideTimeNorm;
[r, meanA, uA, lA] = cmc(A);
RKneeFStrideTimeNorm_CurveMean = meanA;
RKneeFStrideTimeNorm_U95CI = uA;
RKneeFStrideTimeNorm_L95CI = lA;
RKneeFStrideTimeNorm_CMC = r;
clear r;
clear meanA;
clear uA;
clear lA
clear A;

end
