From b0b99ab5c1f1a0c43dad6e3ab267379a260e2f85 Mon Sep 17 00:00:00 2001 From: Lawrence Date: Fri, 5 Mar 2021 13:34:11 -0500 Subject: [PATCH] Select largest selection for findShapes Originally just selected the first possible segment which isn't optimal. Now selects the largest selection first. --- +types/+untyped/+datastub/findShapes.m | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/+types/+untyped/+datastub/findShapes.m b/+types/+untyped/+datastub/findShapes.m index e6341743..3db4ed24 100644 --- a/+types/+untyped/+datastub/findShapes.m +++ b/+types/+untyped/+datastub/findShapes.m @@ -48,13 +48,18 @@ rangeMatches = ismembc(idealRange, indices); startInd = find(rangeMatches, 1); stopInd = find(rangeMatches, 1, 'last'); - if ~all(rangeMatches(startInd:stopInd)) - stopInd = find(~rangeMatches(startInd:stopInd), 1) - 1; + splitPoints = find(~rangeMatches(startInd:stopInd)) + startInd - 1; + if ~isempty(splitPoints) + subStarts = [startInd (splitPoints + 1)]; + subStops = [(splitPoints - 1) stopInd]; + [~, largestSegInd] = max(subStops - subStarts + 1, [], 'linear'); + startInd = subStarts(largestSegInd); + stopInd = subStops(largestSegInd); end subCount = sum(rangeMatches(startInd:stopInd)); if subCount > count - start = indices(startInd); - stop = indices(stopInd); + start = idealRange(startInd); + stop = idealRange(stopInd); step = tempStep; count = subCount; end