Main Content

MATLAB Code Examples

MATLAB® and all MATLAB toolboxes include examples as part of the documentation. To view examples for the current product category, click Examples at the top of the page.

For instance, to view examples demonstrating plotting in MATLAB, navigate to the MATLAB > Graphics > 2-D and 3-D Plots category and click Examples at the top of the page.

Documentation showing the first three MATLAB Graphics 2-D and 3-D Plots examples. The Examples filter at the top of the page is circled.

Additional examples, created by members of the MATLAB community, are available at the File Exchange.

Open Examples in MATLAB

To copy an example and supporting files onto your system and open the example in MATLAB, click the Copy Command button next to the example in the documentation. Then, paste the copied command into the MATLAB Command Window.

You also can open some examples directly in your web browser in MATLAB Online™ by clicking the Try This Example button (if you are not logged into a MathWorks® account) or the Open in MATLAB Online button (if you are logged into a MathWorks account).

Try This Example button and Copy Command button

Once the example is open, run it by clicking Run . To run the example one section at a time and view the incremental results, select the first section and then step through the script by clicking Run and Advance .

See Also

| |

Related Topics

External Websites