matlab file to calculate the variance within and perpendicular to the uncontrolled Manifold.
This file exploit other created matlab functions (thetaGround,projections).
Input: 
        Book.csv files  for each trial being analysed in which the following values normalised to 100% of stance phase 	are 	contained: ankle dorsi/plantarflexion angle, knee flexion/extension, hip flexion/extension, x and y coordinates 		of the heel marker, x and y coordinates of Mid foot Point (mid point between first and fifth metatarsal head)
	
	mean.csv file containing the averages among trials of ankle, knee and hip sagittal angles
	
	Staticvalues.csv containing static parameters: segment lengths and the angles alpha and beta at the rear and front 	part of the foot

the following parameters are to be manually modified in the code:
                                                                   n= degree of freedom
								   d= dimension of task variable
                                                                   N= number of trials
______________________________________

%%Calculates the variance within and perpendicular to the manifold space

% calculation of foot to the ground angles
[thG1]=thetaGround('Book1.csv');
[thG2]=thetaGround('Book2.csv');
[thG3]=thetaGround('Book3.csv');
[thG4]=thetaGround('Book4.csv');
[thG5]=thetaGround('Book5.csv');
[thG6]=thetaGround('Book1B.csv');
[thG7]=thetaGround('Book2B.csv');
[thG8]=thetaGround('Book3B.csv');
[thG9]=thetaGround('Book4B.csv');
[thG10]=thetaGround('Book5B.csv');

%thG calculated are addedd in the csv file in input to be used for the
%following calculations
X1=csvread('Book1.csv');
X2=csvread('Book2.csv');
X3=csvread('Book3.csv');
X4=csvread('Book4.csv');
X5=csvread('Book5.csv');
X6=csvread('Book1B.csv');
X7=csvread('Book2B.csv');
X8=csvread('Book3B.csv');
X9=csvread('Book4B.csv');
X10=csvread('Book5B.csv');
XX1= [X1 thG1];
XX2= [X2 thG2];
XX3= [X3 thG3];
XX4= [X4 thG4];
XX5= [X5 thG5];
XX6= [X6 thG6];
XX7= [X7 thG7];
XX8= [X8 thG8];
XX9= [X9 thG9];
XX10=[X10 thG10];

csvwrite('Book1.csv',XX1,0,0);
csvwrite('Book2.csv',XX2,0,0);
csvwrite('Book3.csv',XX3,0,0);
csvwrite('Book4.csv',XX4,0,0);
csvwrite('Book5.csv',XX5,0,0);
csvwrite('Book1B.csv',XX6,0,0);
csvwrite('Book2B.csv',XX7,0,0);
csvwrite('Book3B.csv',XX8,0,0);
csvwrite('Book4B.csv',XX9,0,0);
csvwrite('Book5B.csv',XX10,0,0);

%add ground angle average of the trials to the mean file as first column
Y1=csvread('mean2.csv');
B=[thG1 thG2 thG3 thG4 thG5 thG6 thG7 thG8 thG9 thG10];
BM=mean(B,2);
BB=[BM Y1];
csvwrite('mean2.csv',BB,0,0);

[TP1,TO1]= projections('mean2.csv','Staticvalues.csv','Book1.csv');
[TP2,TO2]= projections('mean2.csv','Staticvalues.csv','Book2.csv');
[TP3,TO3]= projections('mean2.csv','Staticvalues.csv','Book3.csv');
[TP4,TO4]= projections('mean2.csv','Staticvalues.csv','Book4.csv');
[TP5,TO5]= projections('mean2.csv','Staticvalues.csv','Book5.csv');
[TP6,TO6]= projections('mean2.csv','Staticvalues.csv','Book1B.csv');
[TP7,TO7]= projections('mean2.csv','Staticvalues.csv','Book2B.csv');
[TP8,TO8]= projections('mean2.csv','Staticvalues.csv','Book3B.csv');
[TP9,TO9]= projections('mean2.csv','Staticvalues.csv','Book4B.csv');
[TP10,TO10]= projections('mean2.csv','Staticvalues.csv','Book5B.csv');

TP=cat(2,TP1,TP2,TP3,TP4,TP5,TP6,TP7,TP8,TP9,TP10); %create a single multiarray combining every TP of all the trials
TO=cat(2,TO1,TO2,TO3,TO4,TO5,TO6,TO7,TO8,TO9,TO10); %create a single multiarray combining every TO of all the trials

varTime1=zeros(100,1);
varTime2=zeros(100,1);


n=4;%degree of freedom
d=2;%dimension of task variable
N=10;%number of trials

for k=1:100
  for i=1:N
    for j=1:n
        V1(j,i,k)=TP(j,i,k)*TP(j,i,k);%squared length of each vector parallel to NJ
        V2(j,i,k)=TO(j,i,k)*TO(j,i,k);%squared length of each vector perpendicular to NJ
    end
    SV1(1,i,k)=sum(V1(:,i,k));%sum along each vector of the matrix V1
    SV2(1,i,k)=sum(V2(:,i,k));%sum along each vector of the matrix V2
  end
    SV1T= sum(SV1(:,:,k));% total sum for parallel components
    SV2T= sum(SV2(:,:,k));% total sum for perpendicular components
    varV1=SV1T/((n-d)*N);
    varV2=SV2T/(d*N);
    varTime1(k,1)=varV1;
    varTime2(k,1)=varV2;
end