I have the shortest path connecting a set of points, where the starting point A is fixed. I have the total distance as well as the pairwise distance, as well as the ordered indexes. I want to split the path: if the total distance of the path is greater than a certain value I want to cut it and start a new path and so on.
I managed to achieve it using cumsum
and accummary
(I am using MATLAB ) but it's a really ugly solution, I was wondering is there another way?
Dmax = max(totdistance);
th = Dmax/4; % threshold
toSplit = distances; % pairwise distance
nSplit = cumsum(distances/th);
subs = floor( nSplit ) + 1;
newPaths = accumarray( subs(:), (1:numel(subs)).', [], @(x) {cumsum(toSplit(x))});
This way I can also use the totcost and pairwaise cost, if provided, instead of the distance for example.