MATLAB Code Examples
A standalone example is a readable version of a MATLAB® script or live script that shows how to accomplish a particular task. MATLAB and all MATLAB toolboxes include examples as part of the installed documentation. (Before release R2012b, these examples were called demos.)
To access examples, click Examples at the top of a documentation page. The Help browser displays the examples for the current product category.
MATLAB includes examples that demonstrate various functionalities. 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.
Each example combines comments, code, and output in a formatted document. If you are viewing the documentation in MATLAB, you can open the corresponding script or live script by clicking Open Script or Open Live Script.
If you are viewing the documentation on the web, you can open live script examples using the Live Editor in a web browser. To open the example, click the Try this Example button to the right of the example.
Once it is open, run the example 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 .
Additional examples, created by members of the MATLAB community, are available at the File Exchange.
The product documentation also includes inline code excerpts, such as examples on
function pages like
plot. You can run inline code from the Help browser by selecting the
code, right-clicking, and then selecting Evaluate
Selection, as shown. Evaluating a selection from the Help browser
is not available in MATLAB