- Check the input arguments.
if ((nargin < 6) | (nargin > 8))
help findintconvo
error ('Incorrect number of input arguments.');
end
- Do some initial setup. We need to get the sizes of various
vectors, and initialize vectors that we will fill element by element
later. Initializing vectors to all zero before filling them allows
better memory management by MATLAB.
NumEvenTimes = length(ts_even);
NumFrames = length(midftimes);
fstart = midftimes - (flengths / 2);
TableSize = length (k2_lookup);
integrand = zeros (NumFrames, 1);
if (nargin >= 6); int1 = zeros (1, TableSize); end;
if (nargin >= 7); int2 = zeros (1, TableSize); end;
if (nargin == 8); int3 = zeros (1, TableSize); end;
% if w1 is empty, assume that it should be all ones
if isempty (w1)
w1 = ones (size(NumFrames));
end
- Calculate each element of the integrals, one at a time.
Unfortunately, there does not seem to be any way to vectorize this
operation, and it must therefore be performed within an inefficient
for loop. Since this function can take considerable time to
execute, it prints a period for every iteration of the loop to keep
the user awake.
for i = 1:TableSize
fprintf('.')
exp_fun = exp(-k2_lookup(i) * ts_even);
convo = nconv(Ca_even, exp_fun, ts_even(2) - ts_even(1));
integrand = nframeint (ts_even, convo(1:length(ts_even)),...
fstart, flengths);
% w1 given?
if (nargin >= 6)
int1 (i) = ntrapz(midftimes, (w1 .* integrand));
end
% w2 given?
if (nargin >= 7)
int2 (i) = ntrapz(midftimes, (w2 .* integrand));
end
% w3 given?
if (nargin == 8)
int3 (i) = ntrapz(midftimes, (w3 .* integrand));
end
end