%********************************************************************
%** Testing Matlan execution in technical notes                    **
%** Created by Min-Hua Huang, Jun 19, 2012                         **
%********************************************************************
clear; clc; format long; tic; record=ones(1,21)*-999; 
load trialdata1.mat;  load TRM_result1.mat; a=0; b=1; 
for i=1:1:50
    total=trialdata1(1:n(i),(i-1)*4+1:i*4);
    y=total(:,1); x=total(:,2:4); k=size(x,2);
    xs1=total(:,3)-mean(total(:,3));
    xs2=total(:,4)-mean(total(:,4));
    xs=[xs1 xs2]; nocob=TRM_result1(i,2:4)'; nocos=TRM_result1(i,5);
    trmest=plm(y,xs,[nocob;nocos],a,b);
    trmb=trmest(1,1:3)'; trmsig=trmest(1,4);
    nocoymax=max([ones(n(i),1) xs]*nocob); trmymax=max([ones(n(i),1) xs]*trmb);
    nocoymin=min([ones(n(i),1) xs]*nocob); trmymin=min([ones(n(i),1) xs]*trmb);
    record(i,1)=i; record(i,2)=mu(i); record(i,3)=sigma(i); record(i,4)=a;
    record(i,5)=b; record(i,6)=w(i); record(i,7:10)=[nocob;nocos]'; 
    record(i,11:12)=[nocoymax nocoymin];
    record(i,13:16)=[trmb;trmsig]'; record(i,17:18)=[trmymax trmymin];      
    record(i,19)=trmest(6,3); record(i,20)=max(y); record(i,21)=min(y); 
    display(i); 
end
save overall_result1.mat
toc;