Skip to content

Commit b0b99ab

Browse files
author
Lawrence
committed
Select largest selection for findShapes
Originally just selected the first possible segment which isn't optimal. Now selects the largest selection first.
1 parent 4c355f7 commit b0b99ab

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

+types/+untyped/+datastub/findShapes.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,18 @@
4848
rangeMatches = ismembc(idealRange, indices);
4949
startInd = find(rangeMatches, 1);
5050
stopInd = find(rangeMatches, 1, 'last');
51-
if ~all(rangeMatches(startInd:stopInd))
52-
stopInd = find(~rangeMatches(startInd:stopInd), 1) - 1;
51+
splitPoints = find(~rangeMatches(startInd:stopInd)) + startInd - 1;
52+
if ~isempty(splitPoints)
53+
subStarts = [startInd (splitPoints + 1)];
54+
subStops = [(splitPoints - 1) stopInd];
55+
[~, largestSegInd] = max(subStops - subStarts + 1, [], 'linear');
56+
startInd = subStarts(largestSegInd);
57+
stopInd = subStops(largestSegInd);
5358
end
5459
subCount = sum(rangeMatches(startInd:stopInd));
5560
if subCount > count
56-
start = indices(startInd);
57-
stop = indices(stopInd);
61+
start = idealRange(startInd);
62+
stop = idealRange(stopInd);
5863
step = tempStep;
5964
count = subCount;
6065
end

0 commit comments

Comments
 (0)