% This file is licensed under the Allen Institute Terms of Use, which can be found at:
%http://www.alleninstitute.org/Media/policies/terms_of_use_content.html

%------------------------------------------------------------------------------------

%%%Script to generate plots for Supplement Fig. S6 (matched Gaussian
%synaptic distributions)

clear variables;

fnt = 18;
fntlab = 8;
xtc = [0;50;100;150;200]*10^-3;  %x-axis ticks for time in (ms)
ytc = [0;5;10;15;20]*10^-3; %y-axis ticks for membrane potential in (mV)
xtl = [0;50;100;150;200]; %x-axis labels for time in (ms)
ytl = [0;5;10;15;20]; %y-axis labels for membrane potential in (mV)

ytcsym = [-20;-15;-10;-5;0;5;10;15;20]*10^-3;
ytlsym = [-20;-15;-10;-5;0;5;10;15;20];

set(0,'DefaultFigureWindowStyle','docked');
set(0,'defaultAxesFontName', 'Arial');

scale = 10^3; %to convert from V to mV
scale1= 10^0;
th = 20*10^-3;

load('SuppFigS6_1.mat');

%Parameter sets to run:
mean_std_matrix=[6 6 3 3;2 1 1 0.5]*10^-3;    %First row: means (V), second row: standard deviations (V)

for ii=1:4
    legendstring{ii}=['Mean=' num2str(scale*mean_std_matrix(1,ii)) 'mV, \newline SD=' num2str(scale*mean_std_matrix(2,ii)) 'mV'];
end;

%%%ROW 1: Synaptic distributions set as two Gaussians with two means and two standard deviations

%%%%%SYNAPTIC DISTRIBUTION PLOTS
figure;
s1 = subplot1(2,2,1);
plot(wts_g,scale1*qdw_g(1,:),'.-',wts_g,scale1*qdw_g(2,:),'.-',wts_g,scale1*qdw_g(3,:),'.-',wts_g,scale1*qdw_g(4,:),'.-','MarkerSize',15,'linewidth',2);
axis([0 th 0 scale1*0.18]);
set(gca,'FontSize',fnt);
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
ylabel('Probability');xlabel('synaptic wt (mV) \newline            (a)');
axis square;
leg1 = legend(legendstring);
set(leg1,'FontSize',fntlab,'Interpreter','tex');

%%%%%FIRING RATE PLOTS
s2 = subplot1(2,2,2);
plot(tvec,fout_g','linewidth',2);
set(gca,'FontSize',fnt);
set(gca,'XTick',xtc);
set(gca,'XTickLabel',xtl);
set(gca,'FontSize',fnt);
ylabel('Firing rate (Hz)');xlabel('time (ms) \newline      (b)');
axis square;
leg2 = legend('f_{in} = 250 Hz','f_{in} = 250 Hz','f_{in} = 500 Hz','f_{in} = 500 Hz' );
set(leg2,'FontSize',fntlab,'Interpreter','tex','Location','Southeast');  


%%%ROW 2: Synaptic distributions set as two Gaussians with means on either
%%%side of zero and equal standard deviations

load('SuppFigS6_2.mat');

for ii=1:4
    legendstring{ii}=['Mean=' num2str(scale*mean_std_matrix(1,ii)) 'mV, \newline SD =' num2str(scale*mean_std_matrix(2,ii)) 'mV'];
end;

%%%%%SYNAPTIC DISTRIBUTION PLOTS
s3 = subplot1(2,2,3);
plot(wts_g,scale1*qdw_g(1,:),'.-',wts_g,scale1*qdw_g(2,:),'.-',wts_g,scale1*qdw_g(3,:),'.-',wts_g,scale1*qdw_g(4,:),'.-','MarkerSize',15,'linewidth',2);
axis([-th th 0 scale1*0.1]);
set(gca,'FontSize',fnt);
set(gca,'XTick',ytcsym);
set(gca,'XTickLabel',ytlsym);
set(gca,'FontSize',fnt);
ylabel('Probability');xlabel('synaptic wt (mV) \newline            (c)');
axis square;
leg3 = legend(legendstring);
set(leg3,'FontSize',fntlab,'Interpreter','tex','Location','NorthEast');

%%%%%FIRING RATE PLOTS
s4 = subplot1(2,2,4);
plot(tvec,fout_g','linewidth',2);
axis([0 0.2 0 13]);
set(gca,'FontSize',fnt);
set(gca,'XTick',xtc);
set(gca,'XTickLabel',xtl);
set(gca,'FontSize',fnt);
ylabel('Firing rate (Hz)');xlabel('time (ms) \newline      (d)');
axis square;
%leg4 = legend(legendstring);
%set(leg4,'FontSize',fntlab,'Interpreter','tex','Location', 'East');
leg4 = legend('f_{in} = 250 Hz','f_{in} = 250 Hz','f_{in} = 500 Hz','f_{in} = 500 Hz' );
set(leg4,'FontSize',fntlab,'Interpreter','tex','Location','East');  

print2eps Fig_S6.eps
