I have written codes which generate an n x n distance matrix, but i need help to

generate all the possible paths/permutations without using the perms

function in matlab

For example this is my distance matrix:

This is my distance matrix.

A B C

A 0 29.4109 107.1681

B 29.4109 0 94.8683

C 107.1681 94.8683 0

I want to find the distance of all paths(this is for 3x3matrix)

ABC

ACB

So a 4x4matrix will be

ABCD

ABDC

ACBD

ACDB

ADBC

ADCB