This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -0,0 +1,14 @@
function [S,GS]=gss(a)
% Greatest subsequential sum
a =[0;a(:);0]';
ix1 = find(a(2:end) >0 & a(1:end-1) <= 0);
ix2 = find(a(2:end)<=0 & a(1:end-1) > 0);
K = 0;
S = 0;
for k = 1:length(ix1)
s = sum(a(ix1(k)+1:ix2(k)));
if (s>S)
S=s; K=k;
end;
end;
GS = a(ix1(K)+1:ix2(K));