function current = vstim (voltage,scaling,gain,frequency,varargin);
%
% VSTIM
%
% CURRENT = VSTIM(VOLTAGE, SCALING, GAIN, FREQUENCY)
% uses the columns of the matrix VOLTAGE
% as analog output channels; the input/output
% is done at FREQUENCY. SCALING is the command
% voltage sensitivity set on the amplifier (mV/V),
% and GAIN is the output scaling (V/nA).
%
% CURRENT = VSTIM(VOLTAGE, SCALING, GAIN, FREQUENCY, NREPEAT)
% repeats NREPEAT times
%
% input VOLTAGE is in mV
% output CURRENT is in pA
%
% The A/D output card we use only allows two output channels,
% So we will throw up all over the user if they're giving us
% a VOLTAGE array with more than two rows.
if (size (voltage, 2)) > 2
error('Too many output channels specified! I''m not superhuman!');
end
%
% If an NREPEAT input came, then make VOLTAGE into an
% m by NREPEAT matrix (where m was the original size
% of VOLTAGE)
%
if nargin>4
nrepeat=varargin{1};
voltage=repmat(voltage,nrepeat,1);
end
% Adjust for SCALING. SCALING is specified in mV/V. So in order
% to get p mV output to the cell, we have to output p / SCALING
% volts.
command = voltage / scaling;
% Finally, send to aoi;
aoi_output = aoi(command,[0 1],frequency);
% The output of aoi is volts. To convert to current in pA,
% divide by the gain (V/nA), and multiply by 1000.
current = (aoi_output / gain) * 1000;
% ---------------