Skip to content

Commit

Permalink
Select largest selection for findShapes
Browse files Browse the repository at this point in the history
Originally just selected the first possible segment which isn't optimal. Now selects
the largest selection first.
Lawrence committed Mar 5, 2021
1 parent 4c355f7 commit b0b99ab
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions +types/+untyped/+datastub/findShapes.m
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b0b99ab

Please sign in to comment.