MATLAB Examples

Use array indexing to rasterize text into an existing image.

Create an animation of two growing lines. The animatedline function helps you to optimize line animations. It allows you to add new points to a line without redefining existing points.

This example was authored by the MathWorks community.

Based on "Finite Element Methods for flow problems" of Jean Donea and Antonio Huerta

The c130 function draws a simple 3D airplane modelled after the Lockheed C-130.

Set the random number generator.

By Jarek Tuszynski (jaroslaw.w.tuszynski@leidos.com)

Copyright (c) 2008 Gabriel Peyre

From http://code.google.com/creative/radiohead/:

A convex polytope P can be specified in two ways:

PINPOLYHEDRON: This function is an implementation of a novel algorithm. It tests whether points are inside/outside/on a polyhedron defined by triangular faces and vertices. It can be used

In this example, a 2-dimensional random point set is given, which has an internal cavity. The idea for the concave hull creation is to create the convex hull of the given point set (point set 1)

The cyclic polytope may be defined as the convex hull of vertices on the moment curve . The precise choice of which points on this curve are selected is irrelevant for the combinatorial

How pcolor and surf offset data by one half pixel and discard one row and one column of data. This example shows the effect in pcolor, but the results will be the same with surf.

In this example the convex hull of a relatively large point set is calculated. For this purpose, the initial point set is divided into smaller point sets. The convex hull of each point set is

This function temporarily prints z values corresponding to clicked points on a surface or image. If multiple surfaces or images exist in the same axes, clickz first looks for surfaces and

In this example, a 2-dimensional random point set is given, which has an internal cavity. The idea for the concave mesh creation is to create initially the Delaunay triangulation of the point

In this example, two 2-dimensional random point sets are given. The basic problem of finding the intersection of the two point sets is addressed here. To answer this, the points of both point

In this example, a 2-dimensional gridded point set is given, which has an internal cavity. The idea for the concave hull creation is to create the convex hull of the given point set (point set 1)

Scattered data consists of a set of points X and corresponding values V, where the points have no structure or order between their relative locations. There are various approaches to

In this example, a 2-dimensional point set is given, which has an internal cavity. The points form a uniform grid. The idea for the concave mesh creation is to create initially the Delaunay

The point-in-polyhedron (PIP) problem asks whether each point of an arbitrary point set (query points) lies inside, outside, or on the boundary of the convex hull of another given point set

Using Bessel function of the first kind

Let's start by creating a mountain for our plane to fly by. We'll use Matlab's built-in peaks data for this, and we'll tweak the data set a little bit to set negative elevations to zero and

This function plots a 3D data volume as color-scaled semitransparent surface planes in each dimension.

There exist only 13 manners to split a cube in tetrahedras built exclusively with the 8 corners of the cube without counting simple rotations und reflections of the splittings. There are 12

In this section theoretical details about convex hulls, Delaunay triangulations and Voronoi Diagrams, as well as their implementation in this package are presented.

In this example, two 3-dimensional random point sets are given. The basic problem of finding the intersection of the two point sets is addressed here. To answer this, the points of both point

In this example, two 4-dimensional random point sets are given. The basic problem of finding the intersection of the two point sets is addressed here. To answer this, the points of both point

The point-in-polygon (PIP) problem asks whether each point of an arbitrary point set (query points) lies inside, outside, or on the boundary of the convex hull of another given point set

- 2)Adding A value Boundry To The Extra Grid Points - Using Mosaic Grid Points Value Boundry

From this post on the MATLAB Graphics blog .

This Live Script performs a stress analysis of an aircraft wing and visualizes the results. It relies on a 3D CAD model of an aircraft wing, the analytically-derived wing load profile found in

We will develop and document an analytical model of the loads on the wing of a small passenger aircraft. Using the MATLAB Live Editor we can incorporate math equations, descriptive text, and

From this post on the MATLAB Graphics blog

Create a line plot with markers. Customize the markers by setting these properties using name-value pair arguments with the plot function:

Modify the marker locations, then revert back to the default locations.

Create a line plot with 1,000 data points, add asterisks markers, and control the marker positions using the MarkerIndices property. Set the property to the indices of the data points where

Create a line plot. Display a marker at each data point by including the line-specification input argument when calling the plot function. For example, use '-o' for a solid line with circle

Move a group of objects together along a line using transforms.

Create a scatter plot using blue, semitransparent markers. Then, add a second scatter plot using red, semitransparent markers. Specify the marker color by setting the MarkerFaceColor and

Plot y = x^2\sin(x) . Draw a vertical line at x = 2 from the x -axis to the plotted line.

Plot the sine function and plot two polynomials.

Change the colors used in a filled contour plot.

Specify the line style, color, and markers for two sine waves. If you specify a marker type, then plot adds a marker to each data point.

Use a loop to create a figure containing four subplots. In each subplot, plot a sine wave with different frequencies based on the loop variable k . Add a title to each subplot that includes the

Include a variable value in the x -axis label. Use the num2str function to convert the number to text.

Modify a 3-D bar plot by coloring each bar according to its height.

Label each contour line with its associated value.

Animate a triangle looping around the inside of a circle by updating the data properties of the triangle.

Create a plot using a dashed line. Add the optional line specification, '--' , to the x,y pair.

Plot only the data points by omitting the line style option from the line specification.

Highlight contours at particular levels.

Create a vector of random data and find the index of the minimum and maximum values. Then, create a line plot of the data. Display red markers at the minimum and maximum data values by setting the

Rotate a surface about the y -axis.

Add a legend to a pie chart that displays a description for each slice.

Combine a contour plot and a quiver plot using the hold function.

Combine a line chart and a bar chart using two different y -axes. It also shows how to customize the line and bars.

Display an image using the default coordinate system. Use colors from the colorcube map.

Create a semitransparent bar chart by setting the FaceAlpha property of the bar series object to a value between 0 and 1. Display the grid lines.

Combine a line plot and two stem plots. Then, it shows how to add a title, axis labels, and a legend.

You can modify certain aspects of polar axes in order to make the chart more readable. For example, you can change the grid line locations and associated labels. You also can change the grid

Create a graph in a new figure window, instead of plotting into the current figure.

Display text outside an axes by creating a second axes for the text. MATLAB® always displays text objects within an axes. If you want to place a text description alongside an axes, then you must

Plot a line using the patch function. Set the last entry of y to NaN so that patch creates a line instead of a closed polygon.

Customizing the tick values and labels along an axis can help highlight particular aspects of your data. These examples show some common customizations, such as modifying the tick value

You can control where data appears in the axes by setting the x -axis, y -axis, and z -axis limits. You also can change where the x -axis and y -axis lines appear (2-D plots only) or reverse the

Adjust the color scale of a bivariate histogram plot to reveal additional details about the bins.

Trace a marker along a line by updating the data properties of the marker.

Create a simple line graph. Use the linspace function to define x as a vector of 100 linearly spaced values between 0 and 2\pi .

Combine two semitransparent area charts by setting the FaceAlpha and EdgeAlpha properties for each area object.

Create a chart using the bottom and left sides of the axes for the first plot and the top and right sides for the second plot.

Add text descriptions with arrows that point to three data points on a graph.

Modify properties of the baseline of a bar graph.

Determine the minimum and maximum data points on a graph and add text descriptions next to these values.

Create a simple line plot and add a title to the graph. Include the Greek letter \pi in the title by using the TeX markup \pi .

The hist function accepts bin centers, whereas the histogram function accepts bin edges. To update code to use histogram , you might need to convert bin centers to bin edges to reproduce

Overlay two bar graphs and specify the bar colors and widths. Then, it shows how to add a legend, display the grid lines, and specify the tick labels.

Create a line plot and add a title and axis labels to the graph. Display a superscript in the title using the ^ character. The ^ character modifies the character immediately following it.

Create a pie graph and automatically offset the pie slice with the greatest contribution.

Add a title, axis labels and a legend to a graph using the title , xlabel , ylabel and legend functions. By default, these functions add the text to the current axes. The current axes is typically

Create a surface and vary the transparency based on the gradient of the z data. Use a flat transparency across each surface face by setting the FaceAlpha to 'flat' . Set the surface color to blue

Compare two data sets by overlaying their area graphs.

Specify the line styles and line colors for a plot.

Bar graphs are useful for viewing results over a period of time, comparing results from different data sets, and showing how individual elements contribute to an aggregate amount.

Plot data in polar coordinates. It also shows how to specify the angles at which to draw grid lines and how to specify the labels.

Create a chart with y -axes on the left and right sides using the yyaxis function. It also shows how to label each axis, combine multiple plots, and clear the plots associated with one or both of

Overlay a line plot on a stairstep plot.

Plot two sine waves with different line styles by adding a line specification to each x,y pair.

Plot more than one line by passing multiple x,y pairs to the plot function.

Display the path of a projectile as a function of time using a three-dimensional quiver plot.

The data aspect ratio is the relative length of the data units along the x -axis, y -axis, and z -axis. You can change the aspect ratio using the daspect function. Set the ratio as a three-element

Reduce the size of the bubbles in a geographic bubble chart using the BubbleWidthRange property. (You can also reduce overlapping by resizing the geographic bubble chart figure.)

Use colormaps in MATLAB®.

Create a word cloud from plain text by reading it into a string array, preprocessing it, and passing it to the wordcloud function. If you have Text Analytics Toolbox™ installed, then you can

Get properties of a ruler in MATLAB® and change ruler property values to customize an individual axis in your plot.

Visualize categorical data. The categorical array is used to store data with values from a finite set of discrete categories. A subset of charting types support categorical arrays.

Modify transparency of images, patches and surfaces.

Use animatedline to create an animation of a line that gets longer in every frame.

Create two geographic bubble charts with this same map limits.

Change the location of an axis in MATLAB® to customize your graph. By adjusting the location of an axis, you can display axis lines through the origin.

Convert between video files and sequences of image files using VideoReader and VideoWriter.

Several methods for visualizing volume data in MATLAB®.

Create a variety of 2-D plots in MATLAB®.

Several ways to represent the Earth's topography. The data used in this example are available from the National Geophysical Data Center, NOAA US Department of Commerce under data

Create a variety of 3-D plots in MATLAB®.

Use graphics and font smoothing in MATLAB plots.

Display multiple plots in a single figure in MATLAB® by using subplot .

Create, display, and modify graphics objects in MATLAB®.

The plot box aspect ratio is the relative lengths of the x -axis, y -axis, and z -axis. By default, the plot box aspect ratio is based on the size of the figure. You can change the aspect ratio using

Animate a surface. Specifically, this example animates a spherical harmonic. Spherical harmonics are spherical versions of Fourier series and can be used to model the free oscillations of

Get properties of an axes in MATLAB® and change axes property values to customize your graph.

Create and customize plots with two y -axes.

MATLAB® uses a default color scheme when it displays visualizations such as surface plots. You can change the color scheme by specifying a colormap. For example, here is a surface plot with

Use annotations to add additional information to MATLAB® plots.

Modify properties of a chart with two y -axes by setting ruler properties.

Display mathematical expressions in your MATLAB® plots.

Get properties of a surface plot in MATLAB® and change the property values to customize your plot.

Several techniques to visualize four dimensional (4-D) data in MATLAB®.

You can combine plots in several ways. Combine plots in the same axes, or create multiple axes in a figure.

How MATLAB® uses clipping in plots and how to control clipping.

Create mathematical symbols and special characters for plots and user interfaces using Unicode characters.

When using the default value of C=Z , the colors vary with changes in Z .

Use histogram to effectively view categorical data. You can use the name-value pairs 'NumDisplayBins' , 'DisplayOrder' , and 'ShowOthers' to change the display of a categorical

Get properties of text in MATLAB® and change text property values to customize your plot.

Create complex visualizations using multiple chart types or using overlays of the same chart type.

Geographic bubble charts are a way to visualize data overlaid on a map. For data with geographic characteristics, these charts can provide much-needed context. In this example, you import a

Display an image and convert it to grayscale in MATLAB®.

Add grid lines to a graph. It also describes how to edit the placement of the grid lines and modify their appearance.

Legends are a useful way to label data series plotted on a graph. These examples show how to create a legend and make some common modifications, such as changing the location, setting the font

Specify the colors for a chart with two y -axes by changing the default axes color order.

Create and display the MATLAB® logo.

Create and display a complex three dimensional object and control its appearance.

Colorbars allow you to see the relationship between your data and the colors displayed in your chart. After you have created a colorbar, you can customize different aspects of its

You can use graphics functions in MATLAB to modify tick labels on Cartesian and polar plots.

Heatmaps are a way to visualize data using color. This example shows how to import a file into MATLAB® as a table and create a heatmap from the table columns. It also shows how to modify the

These examples show how to create line plots, scatter plots, and histograms in polar coordinates. They also show how to annotate and change axes limits on polar plots.

Change the data aspect ratio. Then revert back to the default plot box and data aspect ratios using the axis normal command.

Create, display, and modify polar axes in MATLAB®.

Modify properties of a chart with two y -axes by setting Axes properties.

Get properties of a line in MATLAB® and change line property values to customize your plot.

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