MATLAB Examples

The function NUM2WORDS converts a numeric scalar into a string with the number value given in English words, e.g. 1024 -> 'one thousand and twenty-four'. Optional arguments control the

Solves a 2nd order wave equation: utt = uxx + uyy, with u = 0 on the boundaries. It uses a 2nd order central finite difference in time and a Chebyshev spectral method in space (using FFT). The code

We illustrate the use of bipmatch to find maximum matchings in bipartite graphs.

The function NATSORT sorts a cell array of strings (1xN char), taking into account any number values within the strings. This is known as a natural order sort or an alphanumeric sort. Note that

This is a parameter sweep study of a 2nd order ODE system.

This demo illustrates how you would set up and solve an optimization problem (constrained non-linear minimization).

The function WORDS2NUM converts a string (with a number given in English words) into a numeric value, e.g. 'one thousand and twenty-four' -> 1024. Optional arguments control many string

Compiled by Jason Nicholson, Edited by Richard Johnson, Version 1.5, 2018-January-29

Fit an equation to data which has a sudden discontinuity using the Curve Fitting Toolbox.

We demonstrate how to find a minimum dominating set in a graph. This requires Matlab's Optimization Toolbox. We illustrate this using Petersen's graph and a grid graph.

We show how to determine if two graphs are isomorphic and, if so, how to find the permutation that transforms one into the other.

The function ROUND60063 rounds the input numeric values to values from the IEC 60063 "Preferred Numbers" series. Most importantly ROUND60063 simulates the tolerance range of electronic

We illustrate how to find a Hamiltonian cycle in a graph, convert that cycle into a subgraph, and then display the results.

The function NUM2SIP converts a numeric scalar to a string containing the number value with a metric prefix, for example 1000 -> '1 k'. Optional arguments control the number of digits, select

The nanimresize function resizes an image using the Image Processing toolbox function imresize, but first fills NaNs to prevent missing data along NaN boundaries.

We illustrate how to find colorings of graphs and display the results.

The function NATSORTROWS sorts the rows of a cell array of strings (1xN char), taking into account any number values within the strings. This is known as a natural order sort or an alphanumeric

This example was authored by the MathWorks community.

Example 1: Bendat and piersol, Random data, 2010, page 99 Example 4.4

The imagescn behaves just like imagesc, but makes NaNs transparent, sets axis to xy if xdata and ydata are included, and has more error checking than imagesc.

The errorshade function plots a shaded region to indicate gaussian uncertainty. This function works by generating an RGB image of a specified color, and setting transparency of the RGB

The function SIP2NUM converts a string containing a number with a metric prefix into a numeric value, for example '1 k' -> 1000. The function is based on REGEXP, and can detect and convert

The euler_trail function finds Eulerian trails and tours in graphs.

Write a script that tests a function that you create. The example function computes the angles of a right triangle, and you create a script-based unit test to test the function.

Matgraph provides two functions for finding spanning trees:

We specify a finite group by giving a list of its generators. The generators are a cell array of permutations of a common ground set.

Looking at Spring Damper System and comparing the results from the ODE45, ODE23, ODE15s solvers with the analytical solution.

Analyze an idealized 3-D mechanical part under an applied load using Finite Element Analysis (FEA). The objective of the analysis is to determine the maximal deflection caused by the load.

Only scalar variables need apply. Matrices and vectors would not be terribly difficult to implement, but I've not done so.

Author: SHUJAAT KHAN, shujaat@kaist.ac.kr

We show that the the Ramsey number R(4) is greater than 17 by presenting a graph with 17 vertices that has clique and independence numbers equal to three. The Matgraph alpha and omega functions

This demo calculates returns the risk-return relationship in the stock portfolio that is optimal in the mean-variance sense. covMat and expRet are the covariance and mean returns of a

This function prints some quick statistics about a variable in the command window.

This finite element thermal analysis (FEA) examines the heat tolerance for a robotics component of a commercial youBot.

Code File

This is an enhanced version of the regstats function (statistics toolbox). Here are implemented several ways to estimate robust standard errors (se) for the coefficients\n. Also, it

Perform modal and transient analysis of a tuning fork.

We demonstrate how to split the vertex set of a graph into two parts using the split method. The goal is to separate the vertices of the graph into two natural clusters. The splitting is based on

Retrieve it using lasterr. Note the additional line in the error message.

The list can be stored. As long as you can recognise yours, you can remind yourself, while another user would have to guess without having prior knowledge.

Author: Shalin Mehta (c) 2011. shalin.mehta@gmail.com

Many Matgraph functions work with partitions. For example, the color function returns a partition of the vertex set and bipmatch takes a partition as one of its arguments. Matgraph provides

Adaptively evaluate a function on a given range. There are different methods which can be used for choosing where to add new data points. The default method provided by 'adaptive.m' is to add

A MATLAB application from the field of systems biology was chosen for experimental runs. The application was created using SimBiology® which extends MATLAB® with functionality for

Find all points on a gridded surface Z that are farther than some distance from an array of points given by (xpt,|ypt|), then replace the distant points in Z with NaN|s or some declared

Perform a parameter sweep of material properties to determine the material with minimum deflection caused by a given load. Lastly, for such material we compute a load deflection curve. This

Step through and execute this script cell-by-cell to verify the iterator for a CellArrayList.

This function formats long strings into wrapped text of specified width.

Step through and execute this script cell-by-cell to verify a cell array implementation of the List Abstract Data Type (ADT).

In parallel computing, communication between workers extracts a heavy cost and therefore a rule of thumb is to keep processing local. But certain array operations, such as averaging over a

The nantight function sets axis limits to the range of finite data. (2D plots only.) This is similar to the command axis tight; however, nantight only considers the extent of finite data.

The Matgraph package includes a permutation data type. Here we illustrate some of the features of that type.

Write a script-based test that uses local functions as helper functions. The example function approximates the sine and cosine of an angle. The script-based test checks the approximation

Anonymous functions require that you explicitly specify the input arguments as you would for a standard function, separating multiple inputs with commas. For example, this function

Request specific outputs from a function.

Anonymous functions allow you to define a function without creating a program file, as long as the function consists of a single statement. A common application of anonymous functions is to

Is an introduction to the Live Editor. In the Live Editor, you can create live scripts that show output together with the code that produced it. Add formatted text, equations, images, and

Test a function that you create by writing a live script, 'TestRightTriLiveScriptExample.mlx' . The example function computes the angles of a right triangle, and you create a

The following is an example of how to use the Live Editor to create an interactive narrative. Create an interactive narrative to tell a story with computations that you have used to solve a

The following is an example of how to use the Live Editor to accelerate exploratory programming. This example demonstrates how you can use the Live Editor to:

The following is an example of how to use live scripts in the classroom. This example shows how to:

You can add sliders and drop-downs to your live scripts to control variable values interactively. Adding interactive controls to a script is useful when you want to share the script with

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