MATLAB Examples

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

Use array indexing to rasterize text into an existing image.

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

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.

Copyright (c) 2008 Gabriel Peyre

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

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

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

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

This example was authored by the MathWorks community.

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

From this post on the MATLAB Graphics blog .

Using Bessel function of the first kind

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.

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

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)

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

From this post on the MATLAB Graphics blog

Set the random number generator.

Presents the generation of a turbulent wind field in a regular vertical uniform grid. The generated turbulence is assumed

In the example 2, a higher sampling frequency is used with only 49 nodes. The point is to compare the simulated and target power spectral densities (PSDs)

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

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

A convex polytope P can be specified in two ways:

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

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

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

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)

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

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

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

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

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

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.

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

By default, MATLAB interprets text using TeX markup. However, for more formatting options, you can use LaTeX markup instead. For example, you can include mathematical expressions in text

Change the colors used in a filled contour plot.

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.

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

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.

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.

Modify properties of the baseline of a bar graph.

Create a simple line plot and add a title. 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 chart. 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 and axis labels to a chart by using the title , xlabel , and ylabel functions. It also shows how to customize the appearance of the axes text by changing the font size.

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.

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.

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

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

Modify transparency of images, patches and surfaces.

Create two geographic bubble charts with this same map limits.

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

Use graphics and font smoothing in MATLAB plots.

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

MATLAB® uses a default color scheme when it displays visualizations such as surface plots. You can change the color scheme by specifying a colormap. Colormaps are three-column arrays

Annotations are extra information added to a chart to help identify important information. This example first explains the different types of annotations, and then shows you how to add

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

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 using subplots.

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

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

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

Read an RGB image into the workspace and display it. The example then converts the RGB image into a grayscale image and displays it. Finally, the example shows how to combine several

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

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

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

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

You can create a contour plot with emphasis on selected contour lines by splitting the data and creating two overlapping contour plots.

Use a geographic density plot to view the density of cellular tower placement in California.

If you have data that is associated with specific geographic locations, use a geographic axes or chart to visualize your data on a map and provide visual context. For example, if you have data

Create a bar chart with error bars using both the bar and errorbar functions.

View cyclone tracking data in a geographic density plot. The data records observations of cyclones over an 11 year period, between 2007-2017.

Customize the layout of a Geographic Axes.

Create a plot with confidence bounds using the fill function to draw the confidence bounds and the plot function to draw the data points. Use dot notation syntax object.PropertyName to

Add text to a chart, control the text position and size, and create multiline text.

Create a simple line plot and label the axes. Customize the appearance of plotted lines by changing the line color, the line style, and adding markers.

When you create a pie chart, MATLAB labels each pie slice with the percentage of the whole that slice represents. You can change the labels to show different text.

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