ASTAR performs A* search on graph with source, target, weights and heuristics vectors.
Syntax:
[path,cost,heuristic,func,iterations] = astar(source,target,weights,heuristics,names,startNode,goalNode)
[path,cost,heuristic,func,iterations] = astar(source,target,weights,heuristics,startNode,goalNode)
Inputs:
source = Vector or cell array containing starting nodes of each of the edge.
target = Vector or cell array containing ending nodes of each of the edge.
weights = Vector containing weights of each of the edge.
heuristics = Vector containing heuristic values for each node (usually straight line distances).
names = Cell array containing string names of each of the node.
startNode = Initial node in the graph.
goalNode = Goal node in the graph.
Outputs:
path = Cell array containing search path.
cost = Cost of path returned.
heuristic = Heuristic value of last node.
func = Evaluation function value of last node.
iterations = Table containing astar iteration summary.
Example 01:
s = {'A','A','A','B','B','C'};
t = {'B','C','D','E','F','G'};
w = [1 5 3 4 5 9];
h = [5 2 3 6 4 1 0];
[path,cost,heuristic,func,iterations] = astar(s,t,w,h,'A','G')
Example 02:
s = [1 1 1 2 2 3];
t = [2 3 4 5 6 7];
w = [1 5 3 4 5 9];
h = [5 2 3 6 4 1 0];
names = {'A','B','C','D','E','F','G'};
[path,cost,heuristic,func,iterations] = astar(s,t,w,h,n,'A','G')
Example 03:
s = [1 1 1 2 2 3];
t = [2 3 4 5 6 7];
w = [1 5 3 4 5 9];
h = [5 2 3 6 4 1 0];
[path,cost,heuristic,func,iterations] = astar(s,t,w,h,1,7)
Coded by Ali Asghar Manjotho
Lecturer, CSE-MUET
Email: ali.manjotho.ali@gmail.com
Cite As
Ali Asghar Manjotho (2026). A* Search (https://www.mathworks.com/matlabcentral/fileexchange/58589-a-search), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 |
