0001 function s = CumSum(data,stops)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 if nargin < 1,
0029 error('Incorrect number of parameters (type ''help <a href="matlab:help CumSum">CumSum</a>'' for details).');
0030 end
0031 if ~isvector(data),
0032 error('Parameter ''data'' is not a vector (type ''help <a href="matlab:help CumSum">CumSum</a>'' for details).');
0033 end
0034 data = data(:);
0035 if nargin == 2,
0036 if ~isvector(stops),
0037 error('Parameter ''stops'' is not a vector (type ''help <a href="matlab:help CumSum">CumSum</a>'' for details).');
0038 end
0039 stops = logical(stops(:));
0040 if length(stops) ~= length(data),
0041 error('Parameters ''data'' and ''stops'' have different lengths (type ''help <a href="matlab:help CumSum">CumSum</a>'' for details).');
0042 end
0043 end
0044
0045
0046 s = cumsum(data);
0047 if nargin == 1, return; end
0048
0049
0050 stops(1) = 0;
0051 i = find(stops);
0052 k = s(i-1);
0053 dk = diff([0;k]);
0054 z = zeros(size(data));
0055 z(i) = dk;
0056 s = s-cumsum(z);
0057