MATLAB Code Examples

Standalone Examples

A standalone example is a readable version of a MATLAB® script that shows how to accomplish a particular task. MATLAB and all MATLAB toolboxes include examples as part of the installed documentation. (Prior to release R2012b, these examples were called demos.)

Access examples by clicking Examples at the top of the main documentation page for a particular product.

For instance, MATLAB includes a variety of examples that demonstrate mathematics functionality.

Each example combines comments, code, and output together in a formatted document. You can open the corresponding script in the Editor by clicking Open this Example at the top of the page in the Help browser.

In the Editor, there are two ways to run the script:

  • Run 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, .

  • Run the entire script by clicking Run, .

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

Inline Examples

The product documentation also includes inline code excerpts, such as examples on function pages like cos or plot. You can run inline code from the Help browser by selecting the code, right-clicking, and then selecting Evaluate Selection, as shown. (On Macintosh systems, press Shift+F7, which copies code to the Command Window for evaluation.)

See Also

|

Related Examples

External Web Sites

Was this topic helpful?