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

Visualize flight trajectories in a UI figure window using flight instrument components. In this example, you will create and configure standard flight instruments in conjunction with the

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.

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®

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

Execute a forward collision warning (FCW) application with sensor and vision data replayed live via CAN FD and TCP/IP protocols. Recorded data from a sensor suite mounted on a test vehicle

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.

Implement a synthetic data simulation for tracking and sensor fusion in Simulink® with Automated Driving System Toolbox™. It closely follows the Sensor Fusion Using Synthetic Radar and

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

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

Estimate the pose (position and orientation) of a ground vehicle using an inertial measurement unit (IMU) and a monocular camera. In this example, you:

Track extended objects. Extended objects are objects whose dimensions span multiple sensor resolution cells. As a result, the sensors report multiple detections of the extended objects

Implement automatic emergency braking (AEB) with a sensor fusion algorithm by using Automated Driving System Toolbox.

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 trajectories for a driving scenario using Automated Driving System Toolbox™ functions. To create actor and vehicle trajectories interactively instead, use the

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

Convert a fisheye camera model to a pinhole model and construct a corresponding monocular camera sensor simulation. In this example, you learn how to calibrate a fisheye camera and

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

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 cancellation 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.

Most PID tuning rules are based on the assumption that the plant can be approaximated by a first-order plus time delay system. This code explains why this assumption is valid and how to

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.

Show how to set up a listener and callback for a change in price. Note that X_Trader is a 32-bit application and will only work with 32-bit Windows installations of MATLAB.

Most PID tuning rules are based on first-order plus time delay assumption of the plant hence cannot ensure the best control performance. Using mordern optimization techniques, it is

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

Populates a table with market depth information as the prices update. Note that X_Trader is a 32-bit application and will only work with 32-bit Windows installations of MATLAB.

This demo expands on the previous demo to incorporate a larger, intraday trading set (loaded from a database). More data implies more calculations, so we use Parallel Computing Toolbox to

This is a simple demonstration to highlight making use of .NET Assemblies directly in MATLAB.

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 command-line features of anfis on a chaotic time-series prediction example.

Machine learning techniques are often used for financial analysis and decision-making tasks such as accurate forecasting, classification of risk, estimating probabilities of default,

Clustering is a form of unsupervised learning technique. The purpose of clustering is to identify natural groupings of data from a large data set to produce a concise representation based on

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

Use anfis command for nonlinear dynamic system identification.

Do chaotic time series prediction using ANFIS.

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

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

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

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

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

Use Fuzzy C-Means clustering for Iris dataset.

Model the relationship between the number of automobile trips generated from an area and the demographics of the area using the genfis function. Demographic and trip data are from 100

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

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

You can generate code for a Fuzzy Logic Controller block using Simulink® Coder™. For more information on generating code, see 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 Code Generation.

You can generate code for evaluating a fuzzy inference system using MATLAB® Coder™. For more information on generating code, see docid:coder_doccenter#bs2r9ti-1 .

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

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

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

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

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

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.

Design an unconstrained MPC controller that provides performance equivalent to an LQR controller.

Analyze a model predictive controller using cloffset . This function computes the closed-loop, steady-state gain for each output when a sustained, 1-unit disturbance is added to each

Obtain an LTI representation of an unconstrained MPC controller using ss . You can use this to analyze the frequency response and performance of the controller.

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

Specify scale factors in MPC controller to make weight tuning easier.

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

Compute numerical derivatives of a closed-loop cumulated performance index with respect to weights and use them to improve model predictive controller performance.

Guarantee the worst-case execution time of an MPC controller in real-time applications by using the suboptimal solution returned by the optimization solver.

You can simulate the closed-loop response of an MPC controller with a custom quadratic programming (QP) solver in Simulink®.

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

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.

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

Design a model predictive controller for a plant with two inputs and one output with target setpoint for a manipulated variable.

You can review your model predictive controller design for potential stability and robustness problems. To do so:

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

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

Simulate a model predictive controller under a mismatch between the predictive plant model and the actual plant.

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

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

If your plant is nonlinear, a controller designed to operate in a particular target region may perform poorly in other regions. A common way to compensate is to create multiple controllers,

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,

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

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

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

In predictive maintenance algorithm design, you frequently have system data in a plain text format such as comma-separated values (CSV). This example shows how to create and use a

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 presented in the Fault

Detect abrupt changes in the behavior of a system using online estimation and automatic data segmentation techniques. This example uses functionality from System Identification

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

Use a data-based modeling approach for fault detection. This example uses functionality from Signal Processing Toolbox™ and System Identification Toolbox™, and does not require

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

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

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 presented in the Fault

Update an RUL prediction as new data arrives from a machine under test. In the example, you use an ensemble of training data to train an RUL model. You then loop through a sequence of test data

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

This model gets and sets ROS parameters using Simulink®. This example illustrates how to use ROS parameters in Simulink and to share data over the ROS network. An integer value is set as a

Color based object detection

This model shows how to access string parameters and use them to trigger subsystem operations. It gets an image format off the set up ROS parameter server. It is retrieved as a uint8 array that

Use the /turtlebot_move action with a Turtlebot robot. The /turtlebot_move action takes a location in the robot environment and attempts to move the robot to that location.

Requires Computer Vision System Toolbox® and Robotics System Toolbox®.

This model shows how to publish and subscribe to a ROS topic using Simulink®.

Read in a point cloud message from a ROS network. Calculate the center of mass of the coordinates and display the point cloud as an image.

Use a rigid body robot model to compute inverse kinematics using Simulink®. Define a trajectory for the robot end effector and loop through the points to solve robot configurations that

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®

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

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

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

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

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.

Use the Call Service block to call a service on the ROS service server.

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

Use the Read Data block to play back data from a rosbag logfile recorded from a Jackal™ robot from ClearPath Robotics™.

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

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

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.

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

Use Simulink® to control a simulated robot running in a separate ROS-based simulator.

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

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 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

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

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 ( umat objects) by creating uncertain parameters and using them to build matrices. You can then use uncertain matrices to build uncertain state-space models.

You decompose an uncertain model into a fixed certain part and normalized uncertain part using the lftdata command. To see how this command works, create a 2-by-2 uncertain matrix ( umat )

Create uncertain real parameters, modify properties such as range of uncertainty, and sample uncertain parameters.

You can create a 1-by-1 (scalar) positive-real uncertain linear dynamics element, whose frequency response always has real part greater than -0.5. Set the SampleStateDimension property

Create a 4-by-3 uncertain complex matrix ( ucomplexm ), and view its properties. The simplest construction requires only a name and nominal value.

It is possible to form interconnections of uss objects. A common example is to form the feedback interconnection of a given controller with an uncertain plant.

An uncertain parameter has a name (used to identify it within an uncertain system with many uncertain parameters) and a nominal value. Being uncertain, it also has variability, described in

Uncertain frequency responses ( ufrd ) arise naturally when computing the frequency response of an uncertain state-space model ( uss ). They also arise when frequency response data in an frd

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.

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.

Calculate the robust stability and examine the worst-case gain of the closed-loop system described in System with Uncertain Parameters . The following commands construct that system.

You can make substitutions for uncertain elements in uncertain matrices and models using usubs . Doing so is useful for evaluating uncertain objects at particular values of the uncertain

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

When sampling an ultidyn element or an uncertain object that contains a ultidyn element, the result is always a state-space ( ss ) object. The property SampleStateDimension of the ultidyn

The command usample randomly samples the uncertain system at a specified number of points. Randomly sample an uncertain system at 20 points in its modeled uncertainty range. This gives a

You can generate an array from an uncertain object by replacing the uncertain elements with specified values. There are several ways to do this using usubs .

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:

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

Deal with multiple experiments and merging models when working with System Identification Toolbox™ for estimating and refining models.

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

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

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

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

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.

Estimate models using frequency domain data. The estimation and validation of models using frequency domain data work the same way as they do with time domain data. This provides a great

Estimate a transfer function from measured signal data.

Build simple process models using System Identification Toolbox™. Techniques for creating these models and estimating their parameters using experimental data is described. This

Perform and troubleshoot the identification of a SISO system using frequency-response data (FRD). The techniques explained here can also be applied to MIMO models and frequency-domain

Estimate ARMAX and OE-form models using the state-space estimation approach.

Several identification methods available in System Identification Toolbox™. We begin by simulating experimental data and use several estimation techniques to estimate models from the

Estimate the unknown parameters of a discrete-time model.

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