%% Spiking_Models.m
%
%
% - Simulates the following five models, (algorithms from listed program):
%
%       1. Wilson Model (ODE Solver)
%                   --> wilson.m & wilson_ode.m
%
%       2. Hodgkin-Huxley Model
%                   --> hh.m
%
%       3. Leaky Integrate-And-Fire Neurons (Euler's Method)
%                   --> if_sim.m
%
%       4. Eugene Izhikevich's Model of a Physiological Spiking Network
%                   --> IzhichevichNeuron.m
%
%       5. Excitatory Postsynaptic Potentials (EPSP)
%                   --> EPSP.m
%
%
% - Each model has two panels:
%       - parameters (specify model-specific values)
%       - experimental parameters
%               --> switch plots on/off
%               --> specify x-axis limits
%               --> turn currents on/off
%               --> specifiy current values
%
% - All models share the same axes (axes7) on SingleAxis_Panel, with
%   exception to IF and I, which use axes8 and axes9 on the DoubleAxis_Panel as
%   they require two plots
%
% - Reset Button resets model parameters to values given by the original
%   programs found on http://torch.cs.dal.ca/~tt/fundamentals/
%
% - Generally GUI component names are prefixed by a short form of the model's
%   name they belong to:
%       1. Wilson Model (ODE Solver) --> [WIL]
%       2. Hodgkin-Huxley Model --> [HH]
%       3. Leaky Integrate-And-Fire Neurons (Euler's Method) --> [IF]
%       4. Eugene Izhikevich's Model of a Physiological Spiking Network --> [I]
%       5. Excitatory Postsynaptic Potentials (EPSP) --> [EPSP]
%
% - Purpose of variable legendSwitch is to ensure the correct legend is put
%   on a graph, which is dependent upon which variables are graphed. When a
%   checkbox is selected to graph a certain variable, it adds a specified
%   value to legendSwitch. The values have been chosen so that no possible
%   combination of checkboxes will result in the same sum (or product in
%   the case of the Integrate-and-Fire model. Using a switch/case (or an if
%   statement for simple cases), the correct legend is placed on the graph.
%
% - note that the Wilson ODE Solver uses an altered version of wilson_ode.m
%   (all parameter value settings taken out, matricies E, tau, and g are
%   transposed).
%
%
%
%% GUI Setup & Initialization

% initialization - DO NOT EDIT
function varargout = Spiking_Models(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @Spiking_Models_OpeningFcn, ...
    'gui_OutputFcn',  @Spiking_Models_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end

% --- Executes just before Spiking_Models is made visible.
function Spiking_Models_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
set(handles.ButtonGroup,'SelectionChangeFcn',@ButtonGroup_SelectionChangeFcn);
handles=guihandles;

function varargout = Spiking_Models_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;



%% FIGURE, MAIN MENU, AXES, ETC. COMPONENTS
function figure1_KeyReleaseFcn(hObject, eventdata, handles)

% Main menu - allows user to choose a model
% Also sets up GUI components to display properly
function ButtonGroup_SelectionChangeFcn(hObject,eventdata)

handles=guihandles;

% turn off axes
set(handles.SingleAxis_Panel,'Visible','on');
set(handles.DoubleAxis_Panel,'Visible','off');

% turn off model parameters panels
set(handles.WIL_ParametersPanel,'Visible','off');
set(handles.HH_ParametersPanel,'Visible','off');
set(handles.IF_ParametersPanel,'Visible','off');
set(handles.I_ParametersPanel,'Visible','off');
set(handles.EPSP_ParametersPanel,'Visible','off');

% turn off experimental parameters panels
set(handles.HH_EPPanel,'Visible','off');
set(handles.WIL_EPPanel,'Visible','off');
set(handles.I_EPPanel,'Visible','off');
set(handles.IF_EPPanel,'Visible','off');
set(handles.EPSP_EPPanel,'Visible','off');

% next action depends on user's click
switch get(eventdata.NewValue,'Tag')
    case 'WIL_Radio' %
        set(handles.WIL_EPPanel,'Visible','on');
        set(handles.WIL_ParametersPanel,'Visible','on');
    case 'HH_Radio'
        set(handles.HH_ParametersPanel,'Visible','on');
        set(handles.HH_EPPanel,'Visible','on');
    case 'EPSP_Radio'
        set(handles.EPSP_ParametersPanel,'Visible','on');
        set(handles.EPSP_EPPanel,'Visible','on');
    case 'I_Radio'
        set(handles.I_ParametersPanel,'Visible','On');
        set(handles.I_EPPanel,'Visible','on');
        set(handles.SingleAxis_Panel,'Visible','off');
        set(handles.DoubleAxis_Panel,'Visible','on');
    case 'IF_Radio'
        set(handles.IF_ParametersPanel,'Visible','on');
        set(handles.IF_EPPanel,'Visible','on');
        set(handles.SingleAxis_Panel,'Visible','off');
        set(handles.DoubleAxis_Panel,'Visible','on');
end

% closes the GUI
function CloseButton_Callback(hObject, eventdata, handles)
close(handles.figure1);
close all; clear all;


%% WILSON COMPONENTS

% operates when Plot is selected in Wilson ODE Solver
% Uses an altered version of wilson_ode.m
function WIL_PlotButton_Callback(hObject, eventdata, handles)
cla(handles.axes7);
h=waitbar(1/7,'Getting Inputs...');
% finding parameter values from user inputs
g(1)=str2num(get(handles.WIL_KEC,'String'));
g(2)=str2num(get(handles.WIL_CEC,'String'));
g(3)=str2num(get(handles.WIL_KCEC,'String'));
g(4)=str2num(get(handles.WIL_NEC,'String'));
E(1)=str2num(get(handles.WIL_KEP,'String'));
E(2)=str2num(get(handles.WIL_CEP,'String'));
E(3)=str2num(get(handles.WIL_KCEP,'String'));
E(4)=str2num(get(handles.WIL_NEP,'String'));
tau(1)=str2num(get(handles.WIL_KT,'String'));
tau(2)=str2num(get(handles.WIL_CT,'String'));
tau(3)=str2num(get(handles.WIL_KCT,'String'));
minX=str2num(get(handles.WIL_MinX,'String'));
maxX=str2num(get(handles.WIL_MaxX,'String'));
currOn=str2num(get(handles.WIL_CurrentOnAt,'String'));
currOff=str2num(get(handles.WIL_CurrentOffAt,'String'));

if minX<=currOn&&currOn<currOff&&currOff<=maxX
    set(handles.errorString,'String','');
    waitbar(2/7,h,'Equilbration (no external input)...');
    %1: Equilibration: no external input;
    y0=zeros(1,4); y0(4)=-1; param=0; tspan=[0 100]; I_ext=0;
    [t,y]=ode45('wilson_ode',tspan,y0,[],I_ext,g,E,tau);
    
    %2: Integration with no external input
    waitbar(3/7,h,['Integration from t=', num2str(minX), ' to t=', num2str(currOn),'...']);
    I_ext=0;
    y0=y(size(t,1),:); param=10;
    tspan=[minX currOn];
    [t,y]=ode45('wilson_ode',tspan,y0,[],I_ext,g,E,tau);
    I_ext_rec=zeros(length(t),1);
    t_rec=t;
    y_rec=y;
    
    %2: Integration with external input;
    waitbar(4/7,h,['Integration from t=', num2str(currOn), ' to t=', num2str(currOff),'...']);
    I_ext=str2num(get(handles.WIL_Current,'String'));
    y0=y(size(t,1),:); param=0;  tspan=[currOn currOff];
    [t,y]=ode45('wilson_ode',tspan,y0,[],I_ext,g,E,tau);
    I_ext_rec=vertcat(I_ext_rec,ones(length(t),1)*I_ext);
    t_rec=vertcat(t_rec,t);
    y_rec=vertcat(y_rec,y);
    
    %2: Integration with no external input;
    waitbar(5/7,h,['Integration from t=', num2str(currOff),' to t=', num2str(maxX),'...']);
    I_ext=0;
    y0=y(size(t,1),:); param=0;  tspan=[currOff maxX];
    [t,y]=ode45('wilson_ode',tspan,y0,[],I_ext,g,E,tau);
    I_ext_rec=vertcat(I_ext_rec,ones(length(t),1)*I_ext);
    t_rec=vertcat(t_rec,t);
    y_rec=vertcat(y_rec,y);
    
    % Plotting results
    hold(handles.axes7,'on');
    waitbar(6/7, h, 'Plotting...');
    set(handles.axes7,'Position',[10 3 80.4 25]);
    title(handles.axes7,'Wilson Model','Fontsize',12);
    ylabel(handles.axes7,'');
    legendSwitch=0;
    
    % if plot CURRENT is selected
    if (get(handles.WIL_PlotCurrent,'Value'))==1
        plot(handles.axes7,t_rec,I_ext_rec,'b');
        legendSwitch=legendSwitch+1; legend(handles.axes7,'External Current'); end
    
    % if plot VOLTAGE is selected
    if (get(handles.WIL_PlotVoltage,'Value'))==1
        plot(handles.axes7,t_rec,100*y_rec(:,4),'r');
        legendSwitch=legendSwitch+1; legend(handles.axes7,'Voltage [mV]'); end
    
    % if no plots are selected, clear axes
    if (get(handles.WIL_PlotVoltage,'Value'))==0&&(get(handles.WIL_PlotCurrent,'Value'))==0
        cla(handles.axes7); legend(handles.axes7,'hide');
    else % otherwise, label axis
        xlabel(handles.axes7,'Time');
        xlim(handles.axes7,[str2num(get(handles.WIL_MinX,'String')),str2num(get(handles.WIL_MaxX,'String'))]);
    end
    
    % if both plots are selected, legend is changed to incorporate this
    if legendSwitch==2; legend(handles.axes7,'External Current','Voltage [mV]'); end
    waitbar(1,h,'Finished.'); pause(0.5);
    delete(h);
    hold(handles.axes7,'off');
else % if time inputs are not correct, gives error, deletes progress window
    set(handles.errorString,'String','Time input must be MinX<=CurrentOn<=CurrentOff<=MaxX');
    delete(h);
end

function WIL_KCEP_Callback(hObject, eventdata, handles)
function WIL_KCEP_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% resets all values to default, given by program wilson_ode.m
function WIL_ResetButton_Callback(hObject, eventdata, handles)

% resetting model parameters
set(handles.WIL_KEP,'String',num2str(-0.95));
set(handles.WIL_CEP,'String',num2str(1.20));
set(handles.WIL_KCEP,'String',num2str(-0.95));
set(handles.WIL_NEP,'String',num2str(0.50));
set(handles.WIL_KEC,'String',num2str(26));
set(handles.WIL_CEC,'String',num2str(2.25));
set(handles.WIL_KCEC,'String',num2str(9.5));
set(handles.WIL_NEC,'String',num2str(1));
set(handles.WIL_KT,'String', num2str(0.2381));
set(handles.WIL_KCT,'String', num2str(0.0222));
set(handles.WIL_CT,'String', num2str(0.0714));

% resetting plot selections
set(handles.WIL_PlotCurrent,'Value',1);
set(handles.WIL_PlotVoltage,'Value',1);

% resetting experimental parameters
set(handles.WIL_MinX,'String', num2str(0));
set(handles.WIL_MaxX,'String', num2str(200));
set(handles.WIL_Current,'String', num2str(1));
set(handles.WIL_CurrentOnAt,'String',num2str(50));
set(handles.WIL_CurrentOffAt,'String',num2str(150));

% resetting axes
legend(handles.axes7,'hide');
cla(handles.axes7);

function WIL_Current_Callback(hObject, eventdata, handles)
function WIL_Current_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_KEC_Callback(hObject, eventdata, handles)
function WIL_KEC_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_CEC_Callback(hObject, eventdata, handles)
function WIL_CEC_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_KCEC_Callback(hObject, eventdata, handles)
function WIL_KCEC_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_NEC_Callback(hObject, eventdata, handles)
function WIL_NEC_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_KEP_Callback(hObject, eventdata, handles)
function WIL_KEP_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_CEP_Callback(hObject, eventdata, handles)
function WIL_CEP_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_NEP_Callback(hObject, eventdata, handles)
function WIL_NEP_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_KT_Callback(hObject, eventdata, handles)
function WIL_KT_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_CT_Callback(hObject, eventdata, handles)
function WIL_CT_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_KCT_Callback(hObject, eventdata, handles)
function WIL_KCT_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_PlotCurrent_Callback(hObject, eventdata, handles)
function WIL_PlotVoltage_Callback(hObject, eventdata, handles)

function WIL_MinX_Callback(hObject, eventdata, handles)
function WIL_MinX_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_MaxX_Callback(hObject, eventdata, handles)
function WIL_MaxX_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_CurrentOffAt_Callback(hObject, eventdata, handles)
function WIL_CurrentOffAt_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function WIL_CurrentOnAt_Callback(hObject, eventdata, handles)
function WIL_CurrentOnAt_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%% HODGKIN-HUXLEY COMPONENTS
% operates when Plot is selected in the Hodgkin-Huxley Model
function HH_PlotButton_Callback(hObject, eventdata, handles)
% Integration of Hodgkin--Huxley equations with Euler method
cla(handles.axes7);
h=waitbar(1/3,'Getting inputs...');
% finding parameter values from user inputs
% Maximal conductances (in units of mS/cm^2); 1=K, 2=Na, 3=R
g(1)=str2num(get(handles.HH_PCMCInput,'String'));
g(2)=str2num(get(handles.HH_CMCInput,'String'));
g(3)=str2num(get(handles.HH_LCMCInput,'String'));
% Battery voltage ( in mV); 1=n, 2=m, 3=h
E(1)=str2num(get(handles.HH_nInput,'String'));
E(2)=str2num(get(handles.HH_mInput,'String'));
E(3)=str2num(get(handles.HH_hInput,'String'));
% Getting times to switch current on/off
currentOff=str2num(get(handles.HH_CurrentOffAt,'String'));
currentOn=str2num(get(handles.HH_CurrentOnAt,'String'));
% Initialization of some variables
I_ext=0; V=-10; x=zeros(1,3); x(3)=1; t_rec=0;
dt=0.01; % Time step for integration

if str2num(get(handles.HH_MinX,'String'))<=currentOn && currentOn<=currentOff && currentOff<=str2num(get(handles.HH_MaxX,'String'))
    set(handles.errorString,'String','');
    % Integration with Euler method
    waitbar(2/3,h,'Integrating...');
    counter=1;
    for t=-30:dt:str2num(get(handles.HH_MaxX,'String'));
        if t==currentOn; I_ext=str2num(get(handles.HH_Current,'String')); end  % turns external current on at t=XXX
        if t==currentOff; I_ext=0; end   % turns external current off at t=XXX
        % alpha functions used by Hodgkin-and Huxley
        Alpha(1)=(10-V)/(100*(exp((10-V)/10)-1));
        Alpha(2)=(25-V)/(10*(exp((25-V)/10)-1));
        Alpha(3)=0.07*exp(-V/20);
        % beta functions used by Hodgkin-and Huxley
        Beta(1)=0.125*exp(-V/80);
        Beta(2)=4*exp(-V/18);
        Beta(3)=1/(exp((30-V)/10)+1);
        % tau_x and x_0 (x=1,2,3) are defined with alpha and beta
        tau=1./(Alpha+Beta);
        x_0=Alpha.*tau;
        % leaky integration with Euler method
        x=(1-dt./tau).*x+dt./tau.*x_0;
        % calculate actual conductances g with given n, m, h
        gnmh(1)=g(1)*x(1)^4;
        gnmh(2)=g(2)*x(2)^3*x(3);
        gnmh(3)=g(3);
        % Ohm's law
        I=gnmh.*(V-E);
        % update voltage of membrane
        V=V+dt*(I_ext-sum(I));
        % record some variables for plotting after equilibration
        if t>=0;
            t_rec=t_rec+1;
            x_plot(t_rec)=t;
            y_plot(t_rec)=V;
            i_plot(t_rec)=I_ext;
        end
    end  % time loop
    waitbar(2/3,h,'Plotting...');
    % Plotting results
    hold (handles.axes7,'on');
    % set(handles.axes7,'Position',[10 3 80.4 25]);
    ylabel(handles.axes7,'');
    legendSwitch=0;
    title(handles.axes7, 'Hodgkin-Huxley','Fontsize',12);
    % if plot CURRENT is selected
    if (get(handles.HH_PlotCurrent,'Value'))==1
        plot(handles.axes7, x_plot,i_plot,'b');
        legendSwitch=legendSwitch+1; legend(handles.axes7,'External Current'); end
    
    % if plot VOLTAGE is selected
    if (get(handles.HH_PlotVoltage,'Value'))==1
        plot(handles.axes7, x_plot,y_plot,'r');
        legendSwitch=legendSwitch+1; legend(handles.axes7,'Voltage [mV]'); end
    
    % if no plots are selected, clear axes
    if get(handles.HH_PlotCurrent,'Value')==0&&get(handles.HH_PlotVoltage,'Value')==0
        cla(handles.axes7); legend(handles.axes7,'hide');
    else % otherwise, label axis
        legend(handles.axes7,'show');
        xlabel(handles.axes7,'Time');
        xlim(handles.axes7,[str2num(get(handles.HH_MinX,'String')),str2num(get(handles.HH_MaxX,'String'))]);
    end
    
    % if both plots are selected, legend is changed to incorporate this
    if legendSwitch==2; legend(handles.axes7,'External Current','Voltage [mV]'); end
    waitbar(1,h,'Finished.'); pause(0.5);
    delete(h);
    hold (handles.axes7,'off');
else % if time inputs are not correct, gives error, deletes progress window
    set(handles.errorString,'String','Time input must be MinX<=CurrentOn<=CurrentOff<=MaxX');
    delete(h);
end

% resets all parameters to default as given in the program hh.m
function HH_ResetButton_Callback(hObject, eventdata, handles)


% resetting model parameters
set(handles.HH_PCMCInput,'String',num2str(36));
set(handles.HH_CMCInput,'String',num2str(120));
set(handles.HH_LCMCInput,'String',num2str(0.3));
set(handles.HH_nInput,'String',num2str(-12));
set(handles.HH_mInput,'String',num2str(115));
set(handles.HH_hInput,'String',num2str(10.613));
set(handles.HH_Current,'String',num2str(10));

% resetting experimental parameters
set(handles.HH_MinX,'String',num2str(0));
set(handles.HH_MaxX,'String',num2str(500));
set(handles.HH_CurrentOnAt,'String', num2str(10));
set(handles.HH_CurrentOffAt,'String', num2str(40));

% resetting plot options
set(handles.HH_PlotCurrent,'Value',1)
set(handles.HH_PlotVoltage,'Value',1);

% resetting axes
legend(handles.axes7,'hide');
cla(handles.axes7);

function HH_Current_Callback(hObject, eventdata, handles)
function HH_Current_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function HH_PCMCInput_Callback(hObject, eventdata, handles)

function HH_PCMCInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function HH_CMCInput_Callback(hObject, eventdata, handles)
function HH_CMCInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function HH_LCMCInput_Callback(hObject, eventdata, handles)
function HH_LCMCInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function HH_CurrentOnAt_Callback(hObject, eventdata, handles)
function HH_CurrentOnAt_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function HH_nInput_Callback(hObject, eventdata, handles)
function HH_nInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function HH_mInput_Callback(hObject, eventdata, handles)
function HH_mInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function HH_hInput_Callback(hObject, eventdata, handles)
function HH_hInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function HH_PlotCurrent_Callback(hObject, eventdata, handles)
function HH_PlotVoltage_Callback(hObject, eventdata, handles)

function HH_MinX_Callback(hObject, eventdata, handles)
function HH_MinX_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function HH_MaxX_Callback(hObject, eventdata, handles)
function HH_MaxX_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function HH_CurrentOffAt_Callback(hObject, eventdata, handles)
function HH_CurrentOffAt_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end





%% INTEGRATE-AND-FIRE COMPONENTS
% operates when Plot is selected in Integrate-and-Fire
function IF_PlotButton_Callback(hObject, eventdata, handles)
cla(handles.axes8); cla(handles.axes9);
h=waitbar(1/7,'Getting inputs...');
% finding parameter values from user inputs
dt=0.1;                                             % integration time step [ms]
tau=str2num(get(handles.IF_TCInput,'String'));      % time constant [ms]
E_L=str2num(get(handles.IF_RPInput,'String'));      % resting potential [mV]
theta=str2num(get(handles.IF_FTInput,'String'));    % firing threshold [mV]
RI_ext=0;                                           % constant external input [mA/Ohm]

currOn=str2num(get(handles.IF_CurrentOnAt,'String'));
currOff=str2num(get(handles.IF_CurrentOffAt,'String'));
minX=str2num(get(handles.IF_MinX,'String'));
maxX=str2num(get(handles.IF_MaxX,'String'));
if minX<=currOn && currOn<=currOff && currOff<=maxX
    set(handles.errorString,'String','');
    waitbar(2/7,h,['Integrating from t=', str2num(get(handles.IF_MinX,'String')), ' to t=', str2num(get(handles.IF_CurrentOnAt,'String')),'...']);
    % Integration with Euler method
    % current is off. User specifies time current turns from t=0
    t_step=0; v=E_L;
    for t=minX:dt:currOn
        t_step=t_step+1;
        s=v>theta;
        v=s*E_L+(1-s)*(v-dt/tau*((v-E_L)-RI_ext));
        v_rec(t_step)=v;
        t_rec(t_step)=t;
        s_rec(t_step)=s;
        i_rec(t_step)=(RI_ext~=0)*0.5+1;
    end
    
    % current on. User specifies time that current turns on and off, as well as
    % value of the current
    waitbar(3/7,h,['Integrating from t=', str2num(get(handles.IF_CurrentOnAt,'String')), ' to t=', str2num(get(handles.IF_CurrentOffAt,'String')),'...']);
    RI_ext=str2num(get(handles.IF_Current,'String'));
    for t=currOn+dt:dt:currOff
        t_step=t_step+1;
        s=v>theta;
        v=s*E_L+(1-s)*(v-dt/tau*((v-E_L)-RI_ext));
        v_rec(t_step)=v;
        t_rec(t_step)=t;
        s_rec(t_step)=s;
       i_rec(t_step)=(RI_ext~=0)*0.5+1;
    end
    
    % current off. User specifies time that current turns off.
    RI_ext=0;
    waitbar(4/7,h,['Integrating from t=', str2num(get(handles.IF_CurrentOffAt,'String')), ' to t=', str2num(get(handles.IF_MaxX,'String')),'...']);
    for t=currOff+dt:dt:maxX
        t_step=t_step+1;
        s=v>theta;
        i_rec(t_step)=(RI_ext~=0)*0.5+1;
        v=s*E_L+(1-s)*(v-dt/tau*((v-E_L)-RI_ext));
        v_rec(t_step)=v;
        t_rec(t_step)=t;
        s_rec(t_step)=s;
        
    end
    
    waitbar(5/7,h,'Plotting...');
    % Plotting results
    set(handles.SingleAxis_Panel,'Visible','off');
    set(handles.DoubleAxis_Panel,'Visible','on');
    xAxisMin=str2num(get(handles.IF_MinX,'String'));
    xAxisMax=str2num(get(handles.IF_MaxX,'String'));
    xlim(handles.axes8,[xAxisMin xAxisMax]);
    hold(handles.axes8,'on');
    
    % finding legendSwitch
    legendSwitch=ones(1,4);
    legendSwitch(1)=get(handles.IF_PlotSpikes,'Value')*2+1;
    legendSwitch(2)=get(handles.IF_PlotCurrent,'Value')*4+1;
    legendSwitch(3)=get(handles.IF_PlotThreshold,'Value')*6+1;
    legendSwitch(4)=get(handles.IF_PlotVoltage,'Value')*10+1;
    legendSwitch=prod(legendSwitch);
    ylim(handles.axes8,'auto');
    xlabel(handles.axes8,'Time [ms]'); ylabel(handles.axes8,'Voltage [mV]');
    
    % determining if second axes is required for plotting; if so, turns on
    % appropriate GUI components
    if get(handles.IF_PlotSpikes,'Value')==1||get(handles.IF_PlotCurrent,'Value')==1
        set(handles.axes8,'Position',[10 3 80.4 18]);
        set(handles.axes8,'Visible','on');
        set(handles.axes9,'Visible','on');
        hold(handles.axes9,'on');
        title(handles.axes8,'');
        title(handles.axes9,'Integrate-and-Fire','Fontsize',12)
        xlim(handles.axes9,[xAxisMin xAxisMax]); ylim(handles.axes9,[1 2]);
        
    else % turns on other GUI components
        set(handles.axes8,'Position',[10 3 80.4 25]);
        set(handles.axes8,'Visible','on');
        set(handles.axes9,'Visible','off');
        title(handles.axes9,'');
        title(handles.axes8,'Integrate-and-Fire','Fontsize',12);
        if get(handles.IF_PlotSpikes,'Value')==1||get(handles.IF_PlotCurrent,'Value')==1
            ylim(handles.axes8,[1 2]); end
    end
    
    % if plot THRESHOLD is selected
    if get(handles.IF_PlotThreshold,'Value')==1; plot(handles.axes8,[xAxisMin xAxisMax], [theta theta],'b--'); end
    % if plot VOLTAGE is selected
    if get(handles.IF_PlotVoltage,'Value')==1; plot(handles.axes8, t_rec,v_rec,'r'); end
    % if plot CURRENT is selected
    if get(handles.IF_PlotCurrent,'Value')==1; plot(handles.axes9, t_rec,i_rec,'g'); end
    % if plot SPIKES is selected
    if get(handles.IF_PlotSpikes,'Value')==1; plot(handles.axes9, t_rec,s_rec*1.5,'k.','markersize',20); end
    % axis 8/9 switch: turns on/off axes legend
    
    ax9sw=0; ax8sw=0;
    
    % adjusting parameters of axes9.
    if legendSwitch==15||legendSwitch==3||legendSwitch==5 % if only axes 9 required,
        set(handles.axes8,'Visible','off'); xlabel(handles.axes9,'Time [ms]');
    else set(handles.axes8,'Visible','on'); xlabel(handles.axes9,''); end
    
    % legend for axes8, if only VOLTAGE is plotted
    if legendSwitch==165||legendSwitch==33||legendSwitch==55||legendSwitch==11
        legend(handles.axes8,'Voltage [mV]'); ax8sw=1;end
    % legend for axes8, if only THRESHOLD is plotted
    if legendSwitch==7||legendSwitch==21||legendSwitch==35||legendSwitch==7
        legend(handles.axes8,'Threshold [mV]'); ax8sw=1;end
    % legend for axes9, if only CURRENT is plotted
    if legendSwitch==5||legendSwitch==385||legendSwitch==35||legendSwitch==55
        legend(handles.axes9,'Curr. On/Off'); ax9sw=1;end
    % legend for axes9, if only SPIKES are plotted
    if legendSwitch==3||legendSwitch==231||legendSwitch==21||legendSwitch==33
        legend(handles.axes9,'Spikes'); ax9sw=1;end
    % legend for axes 9, if only SPIKES and CURRENT are plotted
    if legendSwitch==15|| legendSwitch==1155||legendSwitch==105||legendSwitch==165
        legend(handles.axes9,'Curr. On/Off','Spikes'); ax9sw=1; end
    % legend for axes 8 if only THRESHOLD and VOLTAGE are plotted
    if legendSwitch==1155||legendSwitch==231||legendSwitch==385||legendSwitch==77
        legend(handles.axes8, 'Threshold [mV]','Voltage [mV]'); ax8sw=1; end
    
    % turning on/off axes legends according to axis 8/9 switches
    if ax9sw==1; legend(handles.axes9,'show'); else legend(handles.axes9,'hide');end
    if ax8sw==1; legend(handles.axes8,'show'); else legend(handles.axes8,'hide'); end
    
    waitbar(1,h,'Finished.'); pause(0.5); delete(h);
    % hold off
    hold(handles.axes9,'off'); hold(handles.axes8,'off');
else % if time inputs are not correct, gives error, deletes progress window
    set(handles.errorString,'String','Time input must be MinX<=CurrentOn<=CurrentOff<=MaxX');
    delete(h);
end

% resets all parameters to default as given in the program if_sim.m
function IF_ResetButton_Callback(hObject, eventdata, handles)

handles=guihandles;
% resetting model parameters
set(handles.IF_TCInput,'String', num2str(10));
set(handles.IF_RPInput,'String', num2str(-65));
set(handles.IF_FTInput,'String', num2str(-55));
set(handles.IF_Current,'String', num2str(12));

% resetting experimental parameters
set(handles.IF_MaxX,'String',num2str(100));
set(handles.IF_MinX,'String',num2str(0));
set(handles.IF_CurrentOnAt,'String',num2str(10));
set(handles.IF_CurrentOffAt,'String',num2str(80));

% resetting plot selections
set(handles.IF_PlotVoltage,'Value',1);
set(handles.IF_PlotThreshold,'Value',1);
set(handles.IF_PlotCurrent,'Value',1);
set(handles.IF_PlotSpikes, 'Value', 1);

% resetting both axes as visible
set(handles.axes8,'Position',[10 3 80.4 25]);
set(handles.axes8,'Visible','on');
set(handles.axes9,'Visible','on');
xlabel(handles.axes9,'');
legend(handles.axes8,'hide'); legend(handles.axes9,'hide');
cla(handles.axes8);
cla(handles.axes9);

function IF_TCInput_Callback(hObject, eventdata, handles)
function IF_TCInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function IF_RPInput_Callback(hObject, eventdata, handles)
function IF_RPInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function IF_FTInput_Callback(hObject, eventdata, handles)
function IF_FTInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function IF_CEIInput_Callback(hObject, eventdata, handles)
function IF_CEIInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function IF_PlotSpikes_Callback(hObject, eventdata, handles)

function IF_MinX_Callback(hObject, eventdata, handles)
function IF_MinX_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function IF_MaxX_Callback(hObject, eventdata, handles)
function IF_MaxX_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function IF_Current_Callback(hObject, eventdata, handles)
function IF_Current_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function IF_CurrentOffAt_Callback(hObject, eventdata, handles)
function IF_CurrentOffAt_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function IF_CurrentOnAt_Callback(hObject, eventdata, handles)
function IF_CurrentOnAt_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function IF_PlotVoltage_Callback(hObject, eventdata, handles)
function IF_PlotCurrent_Callback(hObject, eventdata, handles)
function IF_PlotThreshold_Callback(hObject, eventdata, handles)




%% IZHIKEVICH COMPONENTS
% operates when Plot is selected in Izhikevich's model
% this model has no reset button as parameters are randomized everytime
% plot is selected
function I_PlotButton_Callback(hObject, eventdata, handles)
cla(handles.axes8);
cla(handles.axes9);
h=waitbar(1/4,'Getting inputs...');
% finding parameter values from user inputs
a=str2num(get(handles.I_a,'String'));
b=str2num(get(handles.I_b,'String'));
c=str2num(get(handles.I_c,'String'));
d=str2num(get(handles.I_d,'String'));
v=str2num(get(handles.I_Threshold,'String')); % Initial values of v (threshold)

minX=str2num(get(handles.I_MinX,'String'));
maxX=str2num(get(handles.I_MaxX,'String'));

u=b.*v;               % Initial values of u
firings=[];           % spike timings
I=10;
waitbar(2/4,h,'Calculating...')
if minX<=maxX
    set(handles.errorString,'String','');
    for t=minX:maxX       % simulation of XXX ms
        fired=find(v>=30); % indices of spikes
        if ~isempty(fired)
            firings=[firings; t+0*fired, fired];
            v(fired)=c(fired);
            u(fired)=u(fired)+d(fired);
        end;
        v=v+0.5*(0.04*v.^2+5*v+140-u+I);
        v=v+0.5*(0.04*v.^2+5*v+140-u+I);
        u=u+a.*(b.*v-u);
        v_rec((t-minX)+1)=v;
        s_rec((t-minX)+1)=v>=30;
    end
    
    % plotting results
    waitbar(3/4,h,'Plotting...');
    legendSwitch=get(handles.I_PlotSpikes,'Value') + get(handles.I_PlotVoltage,'Value')*2;

    title(handles.axes9,'Izhikevich','Fontsize',12);
    
    if legendSwitch==2 || legendSwitch==0
        set(handles.axes8,'Position',[10 3 80.4 25]);
        set(handles.axes8,'Visible','on');
        set(handles.axes9,'Visible','off');
        legend(handles.axes9,'hide');
    else
        set(handles.axes8,'Position',[10 3 80.4 18]);
        set(handles.axes8,'Visible','on');
        set(handles.axes9,'Visible','on');
        if legendSwitch==1
            set(handles.axes8,'Visible','off');
            legend(handles.axes8,'hide');
        end
    end
    
    % if plot VOLTAGE is selected
    if legendSwitch==2||legendSwitch==3
        xlabel(handles.axes8, 'Time [ms]');
        plot(handles.axes8, [minX:maxX], v_rec);
        xlim(handles.axes8,[minX maxX]); ylim(handles.axes8, [0 30]);
        legend(handles.axes8,'Voltage [mV]'); legend(handles.axes8,'show');
        
    end
    % if plot SPIKES is selected
    if legendSwitch==1||legendSwitch==3
        plot(handles.axes9, minX:maxX, s_rec*1.5,'k.','markersize',20);
        xlim(handles.axes9,[minX maxX]); ylim(handles.axes9,[1 2]);
        legend(handles.axes9,'Spikes'); legend(handles.axes9,'show');
        title(handles.axes9,'Izhikevich','Fontsize',12);
        title(handles.axes8,'');
    end
    if legendSwitch==0||legendSwitch==2
        title(handles.axes8,'Izhikevich','Fontsize',12);
        title(handles.axes9,'');
    end
    if get(handles.I_PlotSpikes,'Value')==0 && get(handles.I_PlotVoltage,'Value')==0
        legend(handles.axes8,'hide');
        
    end
    waitbar(1,h,'Finished.'); pause(0.5);
    delete(h);
    hold(handles.axes7,'off');
else % if time inputs are not correct, gives error, deletes progress window
    set(handles.errorString,'String','Time input must be MinX<=MaxX');
    delete(h);
end

function I_ResetButton_Callback(hObject, eventdata, handles)

% resetting model parameters
set(handles.I_a,'String',num2str(0.02));
set(handles.I_b,'String',num2str(0.2));
set(handles.I_c,'String',num2str(-65));
set(handles.I_d,'String',num2str(2));
set(handles.I_Threshold,'String',num2str(-65));

% resetting experimental parameters
set(handles.I_MinX,'String',num2str(0));
set(handles.I_MaxX,'String',num2str(1000));

% resetting plot selections
set(handles.I_PlotVoltage,'Value',1);

% resetting axis parameters
legend(handles.axes7,'hide');
cla(handles.axes7);

function I_a_Callback(hObject, eventdata, handles)
function I_a_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function I_b_Callback(hObject, eventdata, handles)
function I_b_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function I_c_Callback(hObject, eventdata, handles)
function I_c_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function I_d_Callback(hObject, eventdata, handles)
function I_d_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function I_Threshold_Callback(hObject, eventdata, handles)
function I_Threshold_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function I_MinX_Callback(hObject, eventdata, handles)
function I_MinX_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function I_MaxX_Callback(hObject, eventdata, handles)
function I_MaxX_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function I_PlotVoltage_Callback(hObject, eventdata, handles)

function I_PlotSpikes_Callback(hObject, eventdata, handles)


%% EPSP COMPONENTS
% operates when Plot is selected in EPSP
function EPSP_PlotButton_Callback(hObject, eventdata, handles)
% Synaptic conductance model to simulate an EPSP
cla(handles.axes7);

h=waitbar(1/4,'Getting inputs...');
% finding parameter values from user inputs
c_m=str2num(get(handles.EPSP_MCInput,'String'));
g_L=str2num(get(handles.EPSP_LCCInput,'String'));
tau_syn=str2num(get(handles.EPSP_SICTCInput,'String'));
E_syn=str2num(get(handles.EPSP_SICRPInput,'String'));
delta_t=str2num(get(handles.EPSP_ITStepInput,'String'));
g_syn(1)=0; I_syn(1)=0; v_m(1)=0; t(1)=0;

if str2num(get(handles.EPSP_MinX,'String'))<=str2num(get(handles.EPSP_MaxX,'String'))
    set(handles.errorString,'String','');
    % Numerical integration using Euler scheme
    waitbar(2/4,h,'Integrating...');
    for i=2:str2num(get(handles.EPSP_MaxX,'String'))/delta_t
        t(i)=t(i-1)+delta_t;
        if abs(t(i)-1)<0.001; g_syn(i-1)=1; end
        g_syn(i)= g_syn(i-1) - delta_t/tau_syn * g_syn(i-1);
        I_syn(i)= g_syn(i) * (v_m(i-1)-E_syn);
        v_m(i) = v_m(i-1) - delta_t/c_m *g_L* v_m(i-1) ...
            - delta_t/c_m * I_syn(i);
    end
    
    waitbar(3/4,h,'Plotting...');
    % Plotting results
    hold(handles.axes7,'on');
    set(handles.axes7,'Position',[10 3 80.4 25]);
    title(handles.axes7,'Excitatory Postsynaptic Potential','Fontsize',12);
    ylabel(handles.axes7,'');
    labelSwitch=0;
    
    % if plot VOLTAGE is selected
    if get(handles.EPSP_PlotVoltage,'Value')==1
        plot(handles.axes7,t,v_m,'b'); labelSwitch=labelSwitch+1; end
    % if plot SYNAPTIC ION CHANNEL CONDUCTANCE is selected
    if get(handles.EPSP_PlotSICC,'Value')==1
        plot(handles.axes7,t,g_syn*5,'r--'); labelSwitch=labelSwitch+3; end
    % if plot CURRENT is selected
    if get(handles.EPSP_PlotCurrent,'Value')==1
        plot(handles.axes7,t,I_syn/5,'k:'); labelSwitch=labelSwitch+5; end
    
    % using labelSwitch to chose an appropriate legend for the axis
    switch labelSwitch
        case 1; legend(handles.axes7,'Membrane Potential');
        case 3; legend(handles.axes7, 'Synaptic Ion Channel Conductance');
        case 4; legend(handles.axes7, 'Membrane Potential', 'Synaptic Ion Channel Conductance');
        case 5; legend(handles.axes7,'Current');
        case 6; legend(handles.axes7, 'Membrane Potential','Current');
        case 8; legend(handles.axes7, 'Synaptic Ion Channel Conductance', 'Current');
        case 9; legend(handles.axes7, 'Membrane Potential', 'Synaptic Ion Channel Conductance', 'Current');
    end
    
    % if no plots are selected, clear axes
    if get(handles.EPSP_PlotCurrent,'Value')==0&&get(handles.EPSP_PlotVoltage,'Value')==0&&get(handles.EPSP_PlotSICC,'Value')==0
        cla(handles.axes7); legend(handles.axes7,'hide');
    else % otherwise, label axis
        xlabel(handles.axes7,'Time [ms]');
        xlim(handles.axes7,[str2num(get(handles.EPSP_MinX,'String')),str2num(get(handles.EPSP_MaxX,'String'))]);
    end
    waitbar(1,h,'Finished.'); pause(0.5);
    delete(h);
    hold(handles.axes7,'off');
else % if time inputs are not correct, gives error, deletes progress window
    set(handles.errorString,'String','Time input must be MinX<=MaxX');
    delete(h);
end

% resets all parameters to default as given in EPSP.m
function EPSP_ResetButton_Callback(hObject, eventdata, handles)

% resetting model parameters
set(handles.EPSP_MCInput,'String',num2str(1));
set(handles.EPSP_LCCInput,'String',num2str(1));
set(handles.EPSP_SICTCInput,'String',num2str(1));
set(handles.EPSP_SICRPInput,'String',num2str(10));
set(handles.EPSP_ITStepInput,'String',num2str(0.01));

% resetting experimental parameters
set(handles.EPSP_MinX,'String',num2str(0));
set(handles.EPSP_MaxX,'String',num2str(10));

% resetting plot selections
set(handles.EPSP_PlotVoltage,'Value',1);
set(handles.EPSP_PlotSICC,'Value',1);
set(handles.EPSP_PlotCurrent,'Value',1);

% resetting axes
legend(handles.axes7,'hide');
cla(handles.axes7);

function EPSP_MCInput_Callback(hObject, eventdata, handles)
function EPSP_MCInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function EPSP_LCCInput_Callback(hObject, eventdata, handles)
function EPSP_LCCInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function EPSP_SICTCInput_Callback(hObject, eventdata, handles)
function EPSP_SICTCInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function EPSP_SICRPInput_Callback(hObject, eventdata, handles)
function EPSP_SICRPInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function EPSP_ITStepInput_Callback(hObject, eventdata, handles)
function EPSP_ITStepInput_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit71_Callback(hObject, eventdata, handles)
function edit71_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function EPSP_PlotVoltage_Callback(hObject, eventdata, handles)
function EPSP_PlotSIC_Callback(hObject, eventdata, handles)
function EPSP_PlotCurrent_Callback(hObject, eventdata, handles)
function EPSP_PlotSICC_Callback(hObject, eventdata, handles)

function EPSP_MinX_Callback(hObject, eventdata, handles)
function EPSP_MinX_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function EPSP_MaxX_Callback(hObject, eventdata, handles)
function EPSP_MaxX_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
