function [ V, t, n_spikes ] = my_IF_model( I, C, V0, Vth, Vreset)
%Compute the voltage for an IF neuron.
%INPUTS:
%  I = input current.
%  C = capacitance.
%  V0 = intial voltage.
%  Vth = threshold voltage
%  Vreset = voltage reset value.
%OUTPUT:
%  V = voltage of IF model.
%  t = time axis.
%  n_spikes = # spikes detected.

dt=0.01;               %Set the timestep.
V(1)=V0;               %Set the initial condition.

n_spikes = 0;                %The # of spikes detected.

for k=1:1000-1                %Compute V, step-by-step.
    V(k+1) = V(k) + dt*I/C;
    if V(k+1) > Vth           %When we cross threshold
        V(k+1) = Vreset;      %...set V to reset
        n_spikes = n_spikes+1;%...and add 1 to spike counter.
    end
end

t = (1:length(V))*dt;

end

