pairedDisplay - a simple user function for online averaging

(author: Taro Kiritani; Feb 2010)

This exemplifies a simple user function. In the userFcns gui it is associated with the 'xsg:dataSaved' event.

What it does: it calculates a running average for the ephys data on both (or multiple) amplifier channels. 

It is necessary to run an initialization routine (initializePairedDisplay) first. This is done in the userFcns gui by associating the function with one of the hotswitches.

function initializePairedDisplay(varargin)
% pairedDisplay - Used to initialize online display of multiple recordings data.
%
% USAGE
%  Use before starting multiple recording experiments. Typically bind with
%  hotswitch.
%
% NOTES
%
% created by Taro Kiritani Feb 2010 tarokiritani2008@u.northwestern.edu
global pairedfig pairedfignum

try
    close(pairedfig)
catch
end
pairedfignum = [];

Here's the code for the pairedDisplay function:

function pairedDisplay(varargin)
% pairedDisplay - Used to implement online display of multiple recordings data.
%
% USAGE
%  Bind this function to the xsg:Save event.
%
% NOTES
%
% created by Taro Kiritani Feb 2010 tarokiritani2008@u.northwestern.edu

global progmanagerglobal pairedfig pairedfignum

% determine whether the figure exists or not. if not, create a new one.
if not(exist('pairedfig','var'))
    pairedfig = figure;
end

try
    figure(pairedfig);
catch
    pairedfig = figure;
end
tracenum = length(struct2cell(progmanagerglobal.programs.ephys.ephys.variables.saveBuffers));

% count the number of traces.
if isempty(pairedfignum)
     pairedfignum = 1;
else
     pairedfignum = pairedfignum + 1;
end

% plot the data.
for n = 1:tracenum
     subplot(tracenum,1,n)
     tracename = ['trace_',num2str(n)];
     trace = getfield(getfield(progmanagerglobal.programs.ephys.ephys.variables.saveBuffers,tracename),'data');

     if pairedfignum == 1
        plot(trace,'k');
     else
        avetrace = get(get(gca,'Children'),'YData')*(pairedfignum-1)/pairedfignum + trace'/pairedfignum;
        plot(avetrace,'r')
     end
end

title(['n = ',num2str(pairedfignum)])
  • No labels