https://se.mathworks.com/help/matlab/ref/polyshape.sortboundaries.html
sortboundaries - Sort polyshape boundaries - MATLAB
This MATLAB function returns a polyshape object whose boundaries are sorted according to the specified criterion and direction.
sortpolyshapeboundariesmatlab