Uniform Cost Search
UCS performs uniform cost search on graph with source, target
and weights vectors.
Syntax:
[path,cost,iterations] = ucs(source,target,weights,names,startNode,goalNode)
[path,cost,iterations] = ucs(source,target,weights,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.
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 minimum search path.
cost = Cost of path returned.
iterations = Table containing ucs 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];
[path,cost,iterations] = ucs(s,t,w,'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];
names = {'A','B','C','D','E','F','G'};
[path,cost,iterations] = ucs(s,t,w,names,'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];
[path,cost,iterations] = ucs(s,t,w,1,7)
Coded by Ali Asghar Manjotho
Lecturer, CSE-MUET
Email: ali.manjotho.ali@gmail.com
Cite As
Ali Asghar Manjotho (2026). Uniform Cost Search (https://www.mathworks.com/matlabcentral/fileexchange/58586-uniform-cost-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 |
