close all force
clear all

%---------------Figure Setup --------------------- 

clear all
close all
  disp('ORTHOSIS')
  set(0, 'DefaultAxesFontSize', 16);
  lw =2.5;  fs = 16;  msize = 10;


 
%--------------- Default Parameters ----------------
time = 1/256:10/256:10;
N=256; II=4; JJ=7; KK=10;

%--------------- Loading the Data -----------------

load 'C:\STAT\ANOVA\ANOVAdat\Ortho.dat'

% 1. COMPUTING THE AVERAGE MODELS

%----------------- Grand Mean ------------------

dYbar = zeros(1,N);
for i = 1:II
    for j=1:JJ
        for k=1:KK
            dYbar = dYbar + Ortho(:, (i-1)*JJ*KK + (j-1)*KK + k )';
        end
    end
end

dYbar=dYbar/(II*JJ*KK);

%------------------------ Figure 1: Functional Grand Mean ---------------------------

figure(1)
set(0, 'DefaultAxesFontSize', 14);
plot(time, dYbar ,'linewidth', lw)
xlabel('Time (s)','fontsize',fs)
ylabel('Grand mean','fontsize',fs)
axis tight

%print -depsc 'C:\BESTAT\ANOVA\ANOVAeps\orthosis1.eps' 
%--------------- Treatment Effects--------------

for i = 1:II
    dYi(i,:) = zeros(1,N);
    for j = (i-1)*JJ + 1: JJ* i
        for k = 1:KK
     dYi(i,:) = dYi(i,:) +   Ortho(:, (j-1)*KK + k )';
        end
    end
end
 
dYi = dYi/(JJ*KK)- repmat(dYbar,II,1); % Note here we have substracted dYbar. Pay attention when computing the standard deviation.
  
%---------------------------- Figure 2 -----------------------

figure(2)
set(0, 'DefaultAxesFontSize', 14);
plot(time(1:5:256), dYi(1,1:5:256),'o', 'markersize', msize) 
hold on
plot(time(1:5:256), dYi(2,1:5:256),'d', 'markersize', msize) 
plot(time(1:5:256), dYi(3,1:5:256),'v', 'markersize', msize) 
plot(time(1:5:256), dYi(4,1:5:256),'*', 'markersize', msize) 
legend('Control','Orthosis','Spring 1','Spring 2',0)
xlabel('Time (s)','fontsize',fs)
ylabel('Treatment effects','fontsize',fs)
axis tight

%print -depsc 'C:\BESTAT\ANOVA\ANOVAeps\orthosis2.eps' 



