File Exchange

image thumbnail

Finding an Optimal Path

version (1.06 MB) by Mary Fenelon
Solve the path planning problem of going through a vector field of wind in the least possible time using MATLAB and Optimization Toolbox.


Updated 09 Apr 2020

View License

This demo shows how to use MathWorks products to solve a path-planning problem.

The objective is to find the optimal path (path of least time) through a randomly generated vector field of wind values.

A Live Script shows how to set up both time-independent and time-dependent versions of the optimization problem.

An app created with App Designer shows an interactive way to do this analysis. The path may be defined by dragging control points with the mouse and the parameters (path distance and time) are updated on-the-fly.

Another Live Script shows how to use MATLAB Coder to generate C/C++ code for the optimization step and compares its run time to that of using MATLAB code.

The scripts and GUIDE app used in the “Finding Optimal Path Using Optimization Toolbox” video by Teja Muppirala are in the R2015b folder.

Cite As

Mary Fenelon (2020). Finding an Optimal Path (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (14)

Very Intuitive to tailor to our specific scenarios

shuang liang

Hi I was wondering how to view the figure

Eric Kappel

Aniq Muhammad


To solve the issue that c4mm11 describes you need to edit the code and remove instances of the nonzero function operating on graphics arrays. Something along the lines of: 'handles.h_ctrlpts(isprop(handles.h_ctrlpts,'Color'))' in place of 'nonzeros(handles.h_ctrlpts)' and similar such instances worked for me.



Hi. I'm getting the following error when I run PathOptimizationDemo.m. Using R2016a.

Undefined function 'nonzeros' for input arguments of type ''.

Error in PathOptimizationDemo>makeInteractiveLine (line 207)

Error in PathOptimizationDemo>pushbutton_NewField_Callback (line 157)

Error in PathOptimizationDemo>PathOptimizationDemo_OpeningFcn (line 72)
pushbutton_NewField_Callback(hObject, eventdata, handles)

Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});

Error in PathOptimizationDemo (line 48)
gui_mainfcn(gui_State, varargin{:});


Muhammad Azam

Julien Bernard

Egor Timme

Jose Luis Ocaña

Tom K


Uploaded the 2.0 version.

R2020a folder: Migrated app to App Designer. Added code generation using MATLAB Coder.
R2015b folder: Fixed GUIDE app.

Updated license

MATLAB Release Compatibility
Created with R2020a
Compatible with any release
Platform Compatibility
Windows macOS Linux