Skip to main content
Engineering LibreTexts

1.4: Editor

  • Page ID
    14911
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    It is tedious to type everything into the command window, not to mention trying to fix any errors. We now look at the Editor, where you will write your Matlab script files (basic programs) and function files (user-defined functions). As with many aspects of Matlab, there are usually many ways to perform a task. To start the Editor window, you can either type edit in the command window or you can click on the “new script” button clipboard_e7829c652fa05cd4d00ff6febac20e0a0.png.

    The Editor is shown below. In the blue bar at the top of this image, you can see that the file is currently Untitled. The asterisk indicates that the file has not been saved since the last change to the file. Try entering the text exactly as shown.

    clipboard_e0520641723e24370f41fda0b479e38fb.png

    There are few more key parts to this file. Any text that follows a percent sign (%) is a comment and is colored green. These are ignored when the program is actually run, but are an important part of the documentation of the file. It is crucial that you document your files properly both to remind yourself what parts of the program do and to inform any other users that may work with the program in the future.

    As you type lines into the program (hitting Enter at the end of the lines), either orange or red lines may appear on the right. You can hover your cursor over these lines to see related messages. In general, orange lines are suggestions, for example, that you should add semicolons on the end of lines to suppress output, or perhaps that another command would be better. Red lines indicate errors. You should pay close attention to these. The messages related to red lines may indicate missing parentheses, a missing “end” to close a loop, or something worse, like improper syntax. In this particular file, we are missing a semicolon in the definition of the variable a (the orange line) and haven’t completed the line for the definition of c (the red line).

    When you save this program, the file name will have a “.m” extension. We refer you to the help files for proper naming conventions of files (and variables in general).


    This page titled 1.4: Editor is shared under a CC BY-NC 3.0 license and was authored, remixed, and/or curated by Troy Siemers (APEX Calculus) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.