Week_1_Part_6_Fundamentals
Week_1_Part_6_Fundamentals
What we've covered this week in Part 5The MATLAB Live Editor
Live Scripts Code Sections Providing Documentation
MATLAB Code FilesWhat we've covered this week in Part 6
Arithmetic operations
Introduction to operator precedence
Making use of built-in Mathematical Functions
The Live Editor is used to write, edit, run, and share MATLAB Live Scripts, which are
sequences of MATLAB commands together with embedded output, formatted text,
equations, and images. Live scripts have a .mlx extension.
You can open the Live Editor and begin a new file by selecting New > Live Script in the
File section of the Home tab on the toolstrip. To open an existing Live Script in the Live
Editor, simply double-click the file in the Current Folder browser.
© 2023 Introduction to Programming in MATLAB (1), Fundamentals 4
The MATLAB Live Editor
The Live Editor window has its own toolstrip, which contains controls for editing,
navigating, running, and formatting your code.
Scripts are used to automate useful blocks of commands. Scripts do not have inputs and
outputs. They operate on data in the workspace, and they can create new data on which
to operate. Variables they create remain in the workspace and can be used in
subsequent computations. Scripts can also produce graphical output by calling
appropriate plotting functions.
Live Scripts display output with the line of code that creates it. By default, MATLAB
displays the output to the right of the code. When you select an output, the cursor
automatically moves to the line of code that generated it.
If a script is displayed in the Live Editor, you can run it by clicking the Run button in the
Run section of the Live Editor tab on the toolstrip. Equivalently, you can press F5.
Running a Live Script runs the code currently shown in the Live Editor, even if the file
contains unsaved changes.
A section consists of a section break and the lines that follow, up to the start of the next
section, which is identified by another section break. You can create a section break by
clicking the Section Break button in the Insert section of the Live Editor tab on the
toolstrip, or by pressing Ctrl+Alt+Enter.
You can use the controls on the Live Editor tab of the toolstrip to navigate from section
to section and evaluate the code in a section.
You can add nonexecutable text in a Live Script by clicking Text button in the Text
section of the Live Editor tab. To return to entering code, you can click the Code button
in the Code section of the Live Editor tab. You can press Alt+Enter to toggle between
entering code and text.
Formatting text in a Live Script is like formatting text in a word processor. Use the
controls in the Live Editor tab to make text bold, italic, underlined, or monospaced, or to
add headings, titles, and bulleted or numbered lists.
The Insert tab also contains buttons to insert equations, images, and hyperlinks. When
you insert one of these items, MATLAB places the item on a new text line directly below
the selected line.
You may want to include text within block of code so you can keep related lines of code
together in a single code block. Text following a percent sign (%) is a comment, or
nonexecutable code. Comments can appear on lines by themselves, or they can be
appended to the end of a line of code.
In these cases, MATLAB scripts can be saved as MATLAB code files which have the
extension .m. Like Live Scripts, these code files allow users to run, edit, and share their
code. Many of the features of live scripts, such as code sections, may be used in
MATLAB code files, unlike Live Scripts however the output of the code is not saved inside
the code file.
• Week_1_Part_6_Fundamentals.mlx