How can I translate this Python code to Matlab
Afficher commentaires plus anciens
def findthepath(graph):
length = len(graph)
adj = list()
for i in range(length):
adj.append(sum(graph[i]))
startpoint = 0
odd = 0
for i in range(length - 1, -1, -1):
if (adj[i] % 2 == 1):
odd += 1
startpoint = i
if (odd > 2):
print("No Solution")
return
stack = list()
path = list()
start = startpoint
while (stack != [] or sum(graph[start]) != 0):
if (sum(graph[start]) == 0):
path.append(start + 1)
start = stack.pop(-1)
else:
for i in range(length):
if graph[start][i] == 1:
stack.append(start)
graph[start][i] = 0
graph[i][start] = 0
start = i
break
for element in path:
print(element, "-> ", end='')
print(start + 1)
'''
graph3 = [[0, 1, 0, 0, 1],
[1, 0, 1, 1, 1],
[0, 1, 0, 1, 0],
[0, 1, 1, 0, 1],
[1, 1, 0, 1, 0]]
findthepath(graph3)
'''
Réponses (1)
Ameer Hamza
le 9 Mai 2018
0 votes
You don't need to translate it to MATLAB. You can directly execute python scripts from MATLAB: https://www.mathworks.com/help/matlab/getting-started-with-python.html. Especially refer to this section .
Catégories
En savoir plus sur Call Python from MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!