MATLAB: Longest simple path between 2D points

algorithmgraphMATLAB

Hello,
Im would like to write a code giving the longest path between a series of points but I'm not sure where to start.
If I have points 1, 2, 3 & 4 with distances between shown in the matrix, how would I go about finding the longest path between these points? I'm fairly sure it would simply be 1-2-3-4 but is it possible to show this in matlab?
Thanks!
x, 1 ,2, 3, 4
1,0,20,12,23
2,20,0,23,15
3,12,23,0,18
4,23,15,18,0
a = [x,1,2,3,4;1,0,20,12,23;2,20,0,23,15;3,12,23,0,18;4,23,15,18,0]

Best Answer

b = a(2:end,2:end);
nn = length(b);
r = perms(1:nn);
cost = 0;
for K = 1 : nn - 1
cost = cost + b(sub2ind(size(b), r(:,K),r(:,K+1)));
end
highcost = max(cost);
matches = find(cost == highcost);
fprintf('longest route cost was %d. There were %d routes that long, which were:\n', highcost, length(matches));
disp(r(matches,:));