Home > analyzePRF > utilities > conv2run.m

conv2run

PURPOSE ^

function f = conv2run(a,b,c)

SYNOPSIS ^

function f = conv2run(a,b,c)

DESCRIPTION ^

 function f = conv2run(a,b,c)

 <a> is a 2D matrix with time x cases
 <b> is a column vector with time x 1
 <c> is a column vector with the same number of rows as <a>.
 elements should be positive integers.

 convolve <a> with <b>, returning a matrix the same size as <a>.
 the convolution is performed separately for each group indicated
 by <c>. for example, the convolution is performed separately
 for elements matching <c>==1, elements matching <c>==2, etc.
 this ensures that there is no convolution bleedage across groups.

 this function is useful for performing convolutions for multiple
 runs (where time does not extend across consecutive runs).

 example:
 a = [1 0 0 4 0 0 1 0 0 0 0]';
 b = [1 1 1 1 1]';
 c = [1 1 1 2 2 2 3 3 3 3 3]';
 f = conv2run(a,b,c);
 [a f]

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function f = conv2run(a,b,c)
0002 
0003 % function f = conv2run(a,b,c)
0004 %
0005 % <a> is a 2D matrix with time x cases
0006 % <b> is a column vector with time x 1
0007 % <c> is a column vector with the same number of rows as <a>.
0008 % elements should be positive integers.
0009 %
0010 % convolve <a> with <b>, returning a matrix the same size as <a>.
0011 % the convolution is performed separately for each group indicated
0012 % by <c>. for example, the convolution is performed separately
0013 % for elements matching <c>==1, elements matching <c>==2, etc.
0014 % this ensures that there is no convolution bleedage across groups.
0015 %
0016 % this function is useful for performing convolutions for multiple
0017 % runs (where time does not extend across consecutive runs).
0018 %
0019 % example:
0020 % a = [1 0 0 4 0 0 1 0 0 0 0]';
0021 % b = [1 1 1 1 1]';
0022 % c = [1 1 1 2 2 2 3 3 3 3 3]';
0023 % f = conv2run(a,b,c);
0024 % [a f]
0025 
0026 % calc
0027 blen = length(b);
0028 
0029 % init
0030 f = zeros(size(a),class(a));
0031 
0032 % loop over cases
0033 for p=1:max(c)
0034   temp = conv2(a(c==p,:),b);
0035   f(c==p,:) = temp(1:end-blen+1,:);
0036 end

Generated on Wed 18-Jun-2014 21:47:41 by m2html © 2005