Creating a function (pathfinding algorithm)
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
How do you create a function:
function [ filled ] = travelDistance ( blank )
where: blank is a two-dimensional array comprised of -1s, 0s and 1s, and filled is blank modified to the specifications below.
To create filled, replace every 0 in blank with its distance to the nearest 1 (staring at 2), traveling along cardinal directions (up, down, left and right) without passing through a -1 value. That is, all 0s that are directly next to a 1 should be changed to a 2 and all 0s next to any new 2s should be changed to 3s, and so on. Spaces with -1 values should be treated as “walls” and should stay -1. If there is no route from a 0 to a 1 without passing through a -1, it should remain a 0. The ultimate result should be that every 0 that is connected to a 1 is replaced with its distance to the nearest 1.
2 comentarios
Respuestas (1)
Image Analyst
el 12 de Oct. de 2017
To do it that way (manually), then fist compute the distance transform with bwdist().
Otherwise, do it automatically with bwdistgeodesic(). See Steve's blog: http://blogs.mathworks.com/steve/2011/11/01/exploring-shortest-paths-part-1/
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!