MATLAB Examples

Create a flight animation for a trajectory using a FlightGear Animation object.

Implement a steady, viscous flow through an insulated, constant-area duct using the Aerospace Toolbox™ software. This flow is also called Fanno line flow.

Visualize aircraft takeoff and chase helicopter with the virtual reality animation object. In this example, you can use the Aero.VirtualRealityAnimation object to set up a virtual

Use the Aerospace Toolbox™ functions to determine heat transfer and mass flow rate in a ramjet combustion chamber.

Visualize simulated versus actual flight trajectories with the animation object (Aero.Animation) while showing some of the animation object functionality. In this example, you can use

Load flight data and estimate G forces during the flight.

Use the method of characteristics and Prandtl-Meyer flow theory to solve a problem in supersonic flow involving expansions. Solve for the flow field downstream of the exit of a supersonic

Visualize contour plots of the calculated values for the Earth's magnetic field using World Magnetic Model 2015 (WMM-2015) overlaid on maps of the Earth. The Mapping Toolbox™ software is

Calculate the required compressor power in a supersonic wind tunnel.

Bring United States Air Force (USAF) Digital DATCOM files into the MATLAB® environment using the Aerospace Toolbox™ software.

Perform glide calculations for a Cessna 172 following Example 9.1 in reference 1 using the Aerospace Toolbox software.

Calculate the Earth's Geoid height using the EGM96 Geopotential Model of the Aerospace Toolbox™ software. It also shows how to visualize the results with contour maps overlaid on maps of the

Use the planetary ephemerides and a Earth Centered Inertial to Earth Centered Earth Fixed (ECI to ECEF) transformation to perform celestial navigation of a marine vessel.

Examine the zonal harmonic, spherical and 1984 World Geodetic System (WGS84) gravity models for latitudes from +/- 90 degrees at the surface of the Earth.

Estimate the analemma of the Sun. The analemma is the curve that represents the variation of the angular offset of the Sun from its mean position on the celestial sphere relative to a specific

Model and simulate the output of an automotive vision sensor for different driving scenarios. Generating synthetic vision detections is important for testing and validating tracking and

Generate ground truth for synthetic sensor data and tracking algorithms. It also shows how to update actor poses in open-loop and closed-loop simulations. Finally, it shows how to use the

Create a variety of road junctions with Automated Driving System Toolbox™ functions. These junctions may be combined with other junctions to create complicated road networks. You can view

Model and simulate the output of an automotive radar sensor for different driving scenarios. Generating synthetic radar detections is important for testing and validating tracking and

Model a radar's hardware, signal processing, and propagation environment for a driving scenario. First you develop a model of the radar transmit and receive hardware, signal processing,

Create actor and vehicle paths for a driving scenario using Automated Driving System Toolbox™ functions. To create actor and vehicle paths interactively instead, use the Driving Scenario

Construct a monocular camera sensor simulation capable of lane boundary and vehicle detections. The sensor will report these detections in vehicle coordinate system. In this example, you

Perform forward collision warning by fusing data from vision and radar sensors to track objects in front of the vehicle.

Generate a scenario, simulate sensor detections, and use sensor fusion to track simulated vehicles. The main benefit of using scenario generation and sensor simulation over sensor

Configure and use a monoCamera object to display information provided in vehicle coordinates on a video display.

Develop an algorithm for the automated marking of lane boundaries in the groundTruthLabeler app.

Use a pretrained semantic segmentation algorithm to segment the sky and road in an image, and use this algorithm to automate ground truth labeling in the groundTruthLabeler app.

Compare ground truth data against results of a lane boundary detection algorithm. It also illustrates how this comparison can be used to tune algorithm parameters to get the best detection

Configure and use a Bird's-Eye Plot to display sensor coverage, detections and tracking results around the ego vehicle.

Evaluate the performance of lane boundary detection against known ground truth. In this example, you will characterize the performance of a lane boundary detection algorithm on a

Generate C code for a MATLAB function that processes data recorded from a test vehicle and tracks the objects around it.

Detect and track multiple vehicles with a monocular camera mounted in a vehicle.

Track pedestrians using a camera mounted in a moving car.

Perform automatic detection and motion-based tracking of moving objects in a video. It simplifies the example Motion-Based Multiple Object Tracking and uses the multiObjectTracker

Detect the ground plane and find nearby obstacles in 3-D Lidar data. This process can facilitate drivable path planning for vehicle navigation.

Train a vision-based vehicle detector using deep learning.

Construct an automated parking valet system. In this example, you learn about tools and techniques in support of path planning, trajectory generation, and vehicle control. For a Simulink®

Estimate free space and create an occupancy grid using semantic segmentation and deep learning. You then use this occupancy grid to create a vehicle costmap.

This case study illustrates Kalman filter design and simulation. Both steady-state and time-varying Kalman filters are considered.

Model objects can represent individual components of a control architecture, such as the plant, actuators, sensors, or controllers. You can connect model objects to build aggregate

Convert a discrete-time system to continuous time using d2c, and compares the results using two different interpolation methods.

Absorbing time delays into frequency response data can cause undesirable phase wrapping at high frequencies.

To reduce the order of a model by pole-zero cancelation at the command line, use minreal .

Convert a time delay in a discrete-time model to factors of 1/_z_.

Create a two-dimensional (2-D) array of transfer functions using for loops. One parameter of the transfer function varies in each dimension of the array.

Compute a reduced-order approximation of a system when the system has unstable or near-unstable poles.

Obtain the closed-loop response of a MIMO feedback loop in three different ways.

Compute a low-order approximation in two ways and compares the results. When you compute a low-order approximation by the balanced truncation method, you can either:

Convert a compensator from continuous to discrete time using several discretization methods, to identify a method that yields a good match in the frequency domain.

Use command-line PID tuning options to reduce overshoot in reference tracking or to improve rejection of a disturbance at the plant input. Using the pidtune command, the example

Insert multichannel analysis points in a generalized state-space model of a MIMO control system.

Compute and plot the response of a state-space ( ss ) model to specified initial state values using initial .

Build a block diagram and insert analysis points at locations of interest using the connect command. You can then use the analysis points to extract various system responses from the model.

Design a two-degree-of-freedom (2-DOF) PID controller at the command line. The example also compares the 2-DOF controller performance to the performance achieved with a 1-DOF PID

Extract SISO control components from a 2-DOF PID controller in each of the feedforward, feedback, and filter configurations. The example compares the closed-loop systems in all

Use the commands for continuous/discrete, discrete/continuous, and discrete/discrete conversions.

The comparison of several techniques for discretizing a notch filter. While control system components are often designed in continuous time, they must generally be discretized for

Construct a Linear Parameter Varying (LPV) representation of a system that exhibits multi-mode dynamics.

Model interconnections of LTI systems, from simple series and parallel connections to complex block diagrams.

How the Control System Toolbox™ lets you represent, manipulate, and analyze any LTI model with a finite number of delays. The delays can be at the system inputs or outputs, between specific

Create continuous-time linear models using the tf , zpk , ss , and frd commands.

Use the command line features of anfis on a chaotic time-series prediction example.

Use a fuzzy system to model the inverse kinematics in a two-joint robotic arm.

Perform fuzzy c-means clustering on 2-dimensional data.

Use anfis command for nonlinear dynamical system identification.

Implement a fuzzy inference system for nonlinear PID control using a 2-D Lookup Table block.

Use Fuzzy Logic Toolbox™ software for image processing. Specifically, this example shows how to detect edges in an image.

This model shows how to implement a fuzzy inference system (FIS) in a Simulink® model.

Use subtractive clustering to model traffic patterns in an area based on the area's demographics.

Do chaotic time series prediction using ANFIS.

Use Fuzzy C-Means clustering for Iris dataset.

Predict of fuel consumption (miles per gallon) for automobiles, using data from previously recorded observations.

Display five defuzzification methods supported in the Fuzzy Logic Toolbox™.

Do adaptive nonlinear noise cancellation using the anfis and genfis commands.

Display 11 membership functions supported in the Fuzzy Logic Toolbox™.

How FCM clustering works using quasi-random two-dimensional data.

Apply the genfis function to model the relationship between the number of automobile trips generated from an area and the area's demographics. Demographic and trip data are from 100 traffic

Adjust the amount of fuzzy overlap when performing fuzzy c-means clustering.

You can construct a Mamdani fuzzy inference system (FIS) at the MATLAB® command line. This method is an alternative to interactively designing your FIS using docid:fuzzy.bu9027w.

You can generate code for a Fuzzy Logic Controller block using Simulink® Coder™. For more information on generating code, see docid:rtw_doccenter.code-generation.

You can generate Structured Text for a Fuzzy Logic Controller block using Simulink® PLC Coder™. For more information on generating Structured Text, see

To illustrate the value of fuzzy logic, examine both linear and fuzzy approaches to the following problem:

Once you have implemented a fuzzy inference system using Fuzzy Logic Designer, using Neuro-Fuzzy Designer, or at the command line, you can simulate the system in Simulink.

How create and test a model predictive controller from the command line.

Design a model predictive controller at the command line using an identified plant model.

Design an MPC controller for a blending process using custom input and output constraints.

Vary the weights on outputs, inputs, and ECR slack variable for soft constraints in real-time.

Design a model predictive controller with look-ahead (previewing) on reference and measured disturbance trajectories.

Vary input and output saturation limits in real-time control. For both command-line and Simulink® simulations, you specify updated input and output constraints at each control interval.

Obtain bumpless transfer when switching model predictive controller from manual to automatic operation or vice versa.

Use the "qp.status" outport of the MPC Controller block in Simulink® to detect controller failures in real time.

Use measurable plant states in MPC control at run time.

Use the "optimal cost" outport of the MPC Controller block to switch between multiple model predictive controllers whose outputs are restricted to discrete values.

Control an unstable aircraft with saturating actuators.

Control a thermo-mechanical pulping (TMP) plant with a model predictive controller.

Design a model predictive controller in MATLAB for a high-fidelity distillation tower model built in Aspen Plus Dynamics®. The controller performance is then verified through

Use constraints on a combination of inputs and outputs to control a nonlinear blending process.

Design a model predictive controller for a DC servomechanism under voltage and shaft torque constraints.

Control a double integrator plant under input saturation in Simulink®.

Design model predictive controller with one measured output, one manipulated variable, one measured disturbance, and one unmeasured disturbance in a typical workflow.

Design a model predictive controller by first from linearizing a nonlinear plant in Simulink® .

Design a model predictive controller for a multi-input multi-output nonlinear plant. The plant has 3 manipulated variables and 2 measured outputs.

Design a model predictive controller with non-zero nominal values.

Uses a model predictive controller (MPC) to control an inverted pendulum on a cart.

Use non-diagonal weight matrices in a model predictive controller.

Design model predictive controller with mixed input/output constraints.

Perform fault diagnosis of a rolling element bearing based on acceleration signals, especially in the presence of strong masking signals from other machine components. The example will

Use a Simulink model to generate fault and healthy data. The fault and healthy data is used to develop a condition monitoring algorithm. The example uses a transmission system and models a

Build a complete Remaining Useful Life (RUL) estimation workflow including the steps for preprocessing, selecting trendable features, constructing a health indicator by sensor fusion,

This examples shows a model parity-equations based approach for detection and diagnosis of different types of faults that occur in a pumping system. This example extends the techniques

Use a data-based modeling approach for fault detection. This example requires Simulink™.

Use an extended Kalman filter for fault detection. The example uses an extended Kalman filter for online estimation of the friction of a simple DC motor. Significant changes in the estimated

This examples shows a model based approach for detection and diagnosis of different types of faults that occur in a pumping system. The example follows the centrifugal pump analysis

Detect abrupt changes in the behavior of a system using online estimation and automatic data segmentation techniques.

Extract features from vibration signals from a ball bearing, conduct health monitoring, and perform prognostics. This example requires Signal Processing Toolbox™.

Build an exponential degradation model to predict the Remaining Useful Life (RUL) of a wind turbine bearing in real time. The exponential degradation model predicts the RUL based on its

Estimate the states of a nonlinear system using an unscented Kalman filter in Simulink™. The example also illustrates how to develop an event-based Kalman filter to update system

In predictive-maintenance algorithm design, you often work with large sets of data collected from operation of your system under varying conditions. The fileEnsembleDatastore object

Generate a data ensemble for predictive-maintenance algorithm design by simulating a Simulink® model of a machine while varying a fault parameter. The example then illustrates some of the

Use a Simulink model to generate fault and healthy data. The data is used to develop a multi-class classifier to detect different combinations of faults. The example uses a triplex

Explores more in-depth interaction with the Gazebo® Simulator from MATLAB®. Topics include creating simple models, adding links and joints to models, connecting models together, and

Demonstrates how to control a robot to follow a desired path using a Robot Simulator. The example uses the Pure Pursuit path following controller to drive a simulated robot along a

Set up the Gazebo® simulator engine. This example prepares you for further exploration with Gazebo and also for exploration with a simulated TurtleBot®.

Demonstrates how to compute an obstacle free path between two locations on a given map using the Probabilistic Roadmap (PRM) path planner. PRM path planner constructs a roadmap in the free

The primary mechanism for ROS nodes to exchange data is to send and receive messages. Messages are transmitted on a topic and each topic has a unique name in the ROS network. If a node wants to

Interact with the Gazebo® Simulator from MATLAB®. It shows how to pause the Gazebo simulation, read the physics properties, and retrieve information about objects in the Gazebo world.

Messages are the primary container for exchanging data in ROS. Topics (see docid:robotics_examples.example-ROSPublishAndSubscribeExample) and services (see

A rosbag or bag is a file format in ROS for storing message data. These bags are often created by subscribing to one or more ROS topics, and storing the received message data in an efficient file

Keyboard control of the TurtleBot® through the use of the ExampleHelperTurtleBotCommunicator class. The instructions describe how to set up the object and how to start the keyboard

Explores MATLAB® control of the Gazebo® Simulator.

A ROS network consists of a single ROS master and multiple ROS nodes. The ROS master facilitates the communication in the ROS network by keeping track of all active ROS entities. Every node

Introduces the TurtleBot® platform and the ways in which MATLAB® users can interact with it. Specifically, the code in this example demonstrates how to publish messages to the TurtleBot

Some commonly used ROS messages store data in a format that requires some transformation before it can be used for further processing. MATLAB® can help you by formatting these specialized

Robot Operating System (ROS) is a communication interface that enables different parts of a robot system to discover, send, and receive data. MATLAB® support for ROS is a library of

ROS supports two main communication mechanisms: topics and services. Topics have publishers and subscribers and are used for sending and receiving messages (see

Connect to a TurtleBot® using the MATLAB® ROS interface. You can use this interface to connect to a wide range of ROS-supported hardware from MATLAB. If you are using a TurtleBot in Gazebo®

Demonstrates an implementation of the VFH+ obstacle avoidance algorithm with the TurtleBot®. The use of timers is explored to expose their power in autonomous algorithms.

In this example, you explore autonomous behavior that incorporates the Kinect® camera. This algorithm involves the TurtleBot® looking for a blue ball and then staying at a fixed distance

Illustrates a collection of ways to apply forces and torques to models in the Gazebo® simulator. First, application of torques is examined in three distinct ways using doors for

Helps you to explore basic autonomy with the TurtleBot®. The described behavior drives the robot forward and changes its direction when there is an obstacle. You will subscribe to the laser

The tf system in ROS keeps track of multiple coordinate frames and maintains the relationship between them in a tree structure. tf is distributed, so that the information about all

Explores how to add and retrieve parameters on the ROS parameter server. The parameter server usually runs on the same device that launches the ROS master. The parameters are accessible

Generate and build a standalone ROS node from a Simulink model.

You can create and analyze uncertain state-space models made up of uncertain state-space matrices. In this example, create a MIMO system with parametric uncertainty and analyze it for

Construct a generalized state-space ( genss ) model of a control system that has both tunable and uncertain parameters. You can use systune to tune the tunable parameters of such a model to

Perform mixed mu-synthesis with the dksyn command in the Robust Control Toolbox™. Here dksyn is used to design a robust controller for a two mass-spring-damper system with uncertainty in

Use Robust Control Toolbox™ to design a multi-input, multi-output controller by shaping the gain of an open-loop response across frequency. This technique is applied to controlling the

Use Robust Control Toolbox™ to design a robust controller (using D-K iteration) and to do robustness analysis on a process control problem. In our example, the plant is a simple two-tank

Use Robust Control Toolbox™ function ncfsyn to improve the stability robustness of a closed-loop system while approximately maintaining the high-gain and low-gain characteristics of

Use the Robust Control Toolbox™ commands usample, ucover and dksyn to design a robust controller with standard performance objectives. It can serve as a template for more complex robust

Use mu-analysis and synthesis tools in the Robust Control Toolbox™. It describes the design of a robust controller for the lateral-directional axis of an aircraft during powered approach

Uses the Robust Control Toolbox™ commands ucover and dksyn to design a high-performance controller for a family of unstable plants.

Uses the hinfstruct command to tune a fixed-structure controller subject to H_\infty constraints.

Use Robust Control Toolbox™ to design a robust controller for an active suspension system.

Use Simulink® blocks and helper functions provided by Robust Control Toolbox™ to specify and analyze uncertain systems in Simulink and how to use these tools to perform Monte Carlo

Use loopmargin to analyze the closed-loop robustness of Simulink models with specified loop-breaking points.

Compute uncertain linearizations using Robust Control Toolbox™ and Simulink® Control Design™. There are two convenient workflows offered depending on how Simulink is used. The

Use Robust Control Toolbox™ to analyze and quantify the robustness of feedback control systems. It also provides insight into the connection with mu analysis and the mussv function.

Use the Robust Control Toolbox™ command ucover to model a family of LTI responses as an uncertain system. This command is useful to fit an uncertain model to a set of frequency responses

Illustrates the pitfalls of using frequency gridding to compute robustness margins for systems with only real uncertain parameters. It presents a safer approach along with ways to

Use uncertain objects in Robust Control Toolbox™ to model uncertain systems and to automate robustness calculations using the robustness analysis tools.

Use Robust Control Toolbox™ to build uncertain state-space models and analyze the robustness of feedback control systems with uncertain elements.

Use Robust Control Toolbox™ to analyze the robustness of an uncertain system with only real parametric uncertainty. You compute the stability margins for a rigid body transport aircraft

Make a Simulink® block linearize to an uncertain variable at the command line. To learn how to specify an uncertain block linearization using the Simulink model editor, see

You create uncertain matrices ( docid:robust_ref.f10-328118 objects) by creating uncertain parameters and using them to build matrices. You can then use uncertain matrices to build

You decompose an uncertain model into a fixed certain part and normalized uncertain part using the docid:robust_ref.f10-120643 command. To see how this command works, create a 2-by-2

Create a periodic random Gaussian input signal using idinput.

Estimate the unknown parameters of a continuous-time model.

Access the estimation report.

Estimate model parameters using linear and nonlinear grey-box modeling.

Represent the structure of the following continuous-time model:

Grey-box modeling of the dynamics of an industrial robot arm. The robot arm is described by a nonlinear three-mass flexible model according to Figure 1. This model is idealized in the sense

The modeling of a measured signal. We analyze the current signal from the R-phase when a 400 kV three-phase transformer is energized. The measurements were performed by Sydkraft AB in

Estimate a transfer function from frequency response data. You use Simulink® Control Design™ to collect frequency response data from a Simulink model and the tfest command to estimate a

Develop and analyze simple models from a real laboratory process data. We start with a small description of the process, learn how to import the data to the toolbox and preprocess/condition

Nonlinear grey-box modeling of vehicle dynamics. Many new vehicle features (like Electronic Stability Programs (ESP), indirect Tire Pressure Monitoring Systems (TPMS), road-tire

Nonlinear black-box modeling of the dynamic behavior of a magneto-rheological fluid damper. It shows how to create Nonlinear ARX and Hammerstein-Wiener models of the damper using

Estimate a transfer function from measured signal data.

The grey-box modeling of a large and complex nonlinear system. The purpose is to show the ability to use the IDNLGREY model to estimate a large number of parameters (16) in a system having many

Linear model identification of a glass tube manufacturing process. The experiments and the data are discussed in:

Computation of bending modes of a flexible wing aircraft. The vibration response of the wing is collected at multiple points along its span. The data is used to identify a dynamic model of the

Create a multi-experiment, time-domain data set by merging only the accurate data segments and ignoring the rest.

Generate output data by simulating a model using an input signal created using idinput .

Create a multiexperiment iddata object by merging iddata objects, where each contains data from a single experiment or is a multiexperiment data set.

Estimate parameters in user-defined model structures. Such structures are specified by IDGREY (linear state-space) or IDNLGREY (nonlinear state-space) models. We shall investigate

Illustrates how models simulated in Simulink® can be identified using System Identification Toolbox™. The example describes how to deal with continuous-time systems and delays, as well

Manage data and model objects available in the System Identification Toolbox™. System identification is about building models from data. A data set is characterized by several pieces of

Obtain linear approximations of a complex, nonlinear system by means of linear model identification. The approach is based on selection of an input signal that excites the system. A linear

The benefits of regularization for identification of linear and nonlinear models.

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Contact your local office