function RastorPlot(matrix,threshold,fig,varargin);
% RastorPlot takes as an input a matrix containing the outputs of a set of
% neurons.  each row is a neuron, each column is a vector.  This becomes
% slightly confusing, because rastor plots are aligned the other way.  It
% can take an optional second input of which figure number to plot in.

%first, invert the matrix
RMatrix = matrix';
% Now, each row is a time step, each column is a neuron
if nargin >=2
elseif nargin == 1
    threshold = 0.5
end

if nargin == 3,
    figure(fig)
    axesHandle = axes;
    set(axesHandle,'YMinorGrid','on');
%     set(axesHandle,'YMinorTick','on');
%     set(axesHandle,'YTick',1:1:length(matrix(1,:)));
%     set(axesHandle,'YTickLabel','');
end
hold on 
% plotterY = length(matrix(1,:));
plotterY = -1;
for time = 1: length(matrix(1,:))
    plotterX = find(RMatrix(time,:)>= threshold);
    if isempty(plotterX) == 0
        Ycords = plotterY * ones(length(plotterX));
        plot(plotterX,Ycords,'bx')
    end
    plotterY = plotterY-1;
end

end