-
1 Comment
Hee Jason
on 27 Nov 2020
function y = lengthOnes(x)
y = double(x == '1');
L = numel(y);
A = tril(ones(L,L));
C = mat2cell(A,ones(1,L),L);
D = cellfun(@(c) conv(c,y),C,"UniformOutput",false);
E = cellfun(@(c) sum(c),C);
F = cellfun(@(c) max(c),D);
R = max(E(F == E));
if(isempty(R))
y = 0;
else
y = R;
end
end
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!