global flip;
global iteration;
global Hin_ToFlip;
global IPTG;
global Xylose;
global Arabinose;

iteration=0;
flip=0; % Hin is from left to right
Hin_ToFlip=60; % Assumed that at 60 nM Hin flips DNs segments



% % Also Works
% IPTG=1000;
% Xylose=1000;
% Arabinose=0;
% tspan=[0 5000]; % Simulate for 3000 sec
% [plott ploty]=ode15s(@StochasticSwitch,tspan,StochasticSwitch_initial_values);
% plot(plott,ploty)
% legend ('mRNA_LacI', 'LacI','IPTG_LacI','mRNA_XylR','XylR','Xylose_XylR','mRNA_Rfp','Rfp','mRNA_Gfp','Gfp','mRNA_Hin_RightToLeft','Hin','mRNA_Hin_LeftToRight','mRNA_AraR','AraR','Arabinose_AraR','mRNA_SspB','SspB','SspB_Hin')
%  
IPTG=0;
Xylose=0;
Arabinose=10000;

Size=10;
GfpMatlabVector=zeros(68,1);
GfpResultVector=zeros(Size * Size,1);
IPTGResultVector=zeros(Size * Size,1);
XyloseResultVector=zeros(Size * Size,1);
RfpResultVector=zeros(Size * Size,1);

Step=1000;
for i = 1:Size
    IPTG= (i-1) * Step;
    %IPTG=1000;
    for j=1:Size 
        index=j + (i-1)*Size;
        IPTGResultVector(index)=IPTG;              
        Xylose= (j-1) * Step;
        %Xylose=1000;
        XyloseResultVector(index)=Xylose; 
        tspan=[0 5000]; % Simulate for 3000 sec
        [plott ploty]=ode15s(@StochasticSwitch,tspan,StochasticSwitch_initial_values);
        %Result_vectorSize=size(ploty);    
        %GfpResultVector(index)= ploty(Result_vectorSize(1),10);%Get the last Gfp result, steady state level of Gfp 
        %plot(plott,ploty)
        %legend ('mRNA_LacI', 'LacI','IPTG_LacI','mRNA_XylR','XylR','Xylose_XylR','mRNA_Rfp','Rfp','mRNA_Gfp','Gfp','mRNA_Hin_RightToLeft','Hin','mRNA_Hin_LeftToRight','mRNA_AraR','AraR','Arabinose_AraR','mRNA_SspB','SspB','SspB_Hin')
        GfpColumn=ploty(:,10);
        RfpColumn=ploty(:,8);
        GfpResultVector(index)=GfpColumn(length(GfpColumn));
        RfpResultVector(index)=RfpColumn(length(RfpColumn));
        
       
    end    
end
%ploty
IPTGResultVector;
XyloseResultVector;
GfpResultVector;
RfpResultVector;

 Result=zeros(Size *Size, 4);
 Result(:,1)=IPTGResultVector;
 Result(:,2)=XyloseResultVector;
 Result(:,3)=GfpResultVector;
 Result(:,4)=RfpResultVector;
 
 
 
xlswrite('ssdata10_arabinose_10000__1.xls',Result,'A');
Result
