60 lines
2.0 KiB
Matlab

function output = anadata(obj, varargin)
%ANADATA Get the analog data from a PricklyPear run
% anadata(PP) returns the analog data (membrane potential) of the soma
% from a PricklyPear simulation run (therefore, PP needs an experiment
% and irec).
%
% anadata(PP, channel) specifies the recording channel (c, d0d, ad...).
%
% anadata(PP, channel, metric) specifies the metric (vm).
%
% anadata(..., 'spt', spt) removes the spikes at spt (ms) by using
% linear interpolation over a [-1 1.2] ms window.
%
% anadata(..., 'spwin', [-1 1.2]) specifies the time window (ms) to be used
% for linear interpolation when suppressing spikes.
% Handle input
p = inputParser();
p.addOptional('channel', 'c', @ischar);
p.addOptional('metric', 'vm', @ischar);
p.addParamValue('spt', []);
p.addParamValue('spwin', [-1 1.2]);
p.parse(varargin{:});
p = p.Results;
% The object must be a specific run
assert(~isempty(experiment(obj)), 'Please specify an experiment');
assert(~isempty(irec(obj)), 'Please specify a specific run');
% Requested variables must be correct
assert(any(strcmp([obj.sim_channels {'all'}], p.channel)), sprintf('"%s" is not a valid channel', p.channel));
assert(any(strcmp([obj.sim_metrics {'all'}], p.metric)), sprintf('"%s" is not a valid metric', p.metric));
% Handle output
output = {};
% Generate the filename
if obj.irec == 0
fname = fullfile(obj.datadir(), sprintf('run_unsaved__vm_%s.txt', p.channel));
else
fname = fullfile(obj.datadir(), sprintf('run_%05i__vm_%s.txt', obj.irec, p.channel));
end
% Read it if it exists
if exist(fname, 'file')
txt = fileread(fname);
data = textscan(txt, '%f', 'Delimiter', '\n');
output = data{1};
output(end) = [];
else
error('Data was not found');
end
% Remove spikes
if ~isempty(p.spt)
output = cutFromWaveform(obj.dt, output, p.spt, p.spwin);
end
end