



CORE_RESETINTEGRATOR Core computational routine for RESETINTEGRATOR.
Y = CORE_RESETINTEGRATOR(X,R) takes length N vectors X and R, where X
is of type double and R is of type LOGICAL and returns a length N
vector Y such that Y(j) = / Y(j-1) + X(j), if R(j) == 1
\ 0 , if R(j) == 0
The matrix Y is of type double.
CONDITIONS
----------
X must be a matrix of type DOUBLE.
X can not be sparse.
X should not contain NaN or Inf values; the results will be compiler
dependent.

0001 function Y = CORE_resetintegrator(X,R) 0002 %CORE_RESETINTEGRATOR Core computational routine for RESETINTEGRATOR. 0003 % Y = CORE_RESETINTEGRATOR(X,R) takes length N vectors X and R, where X 0004 % is of type double and R is of type LOGICAL and returns a length N 0005 % vector Y such that Y(j) = / Y(j-1) + X(j), if R(j) == 1 0006 % \ 0 , if R(j) == 0 0007 % 0008 % The matrix Y is of type double. 0009 % 0010 % CONDITIONS 0011 % ---------- 0012 % X must be a matrix of type DOUBLE. 0013 % X can not be sparse. 0014 % X should not contain NaN or Inf values; the results will be compiler 0015 % dependent. 0016 0017 Y = zeros(size(X)); 0018 if (R(1)), Y(1) = X(1); 0019 else Y(1) = 0; 0020 end 0021 for t = 2:length(X) 0022 if (R(t)), Y(t) = Y(t-1) + X(t); 0023 else Y(t) = 0; 0024 end 0025 end 0026 0027 return; 0028 0029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% TEST CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0032 % N = 1e6; data = rand(N,1); reset = (rand(N,1) > 0.01); 0033 % tic; int = CORE_resetintegrator(data,reset); t = toc; 0034 % err = [diff([0; int]) - data].^2; err(~reset) = NaN; 0035 % printf('\nCORE_resetintegrator took %5.3f sec with MSE %g.', t, nanmean(err)); 0036 % if (~all(int(~reset)==0)), printf('Resetting failed.'); end;