Skip to main content
Engineering LibreTexts

1.6: Editor Tips

  • Page ID
    14913
  • \( \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}}\)

    Here we include some tips and keyboard shortcuts that come up often and can save time. Note that many of these are accessible by using the right mouse button while in the Editor.

    Block Commenting
    Instead of deleting code, it is often adventageous to simply “comment it out” for later editing. To do this, simply highlight the code that you wish to comment out and use Ctrl + R. Note that if you only want to comment out a single line, just make sure your cursor is on the line and use Ctrl + R (you don’t have to highlight the whole line). You can uncomment any of these later by highlighting any comment lines and using Ctrl + T.

    Running Code
    There are several ways to execute your files, but there are a few short-cuts when running script files. To run the entire file, you can either use the F5 key or click on the green “run” button clipboard_e122caa07ade8e4f7acd3857a696bf7e5.png. To see how smaller blocks of code may run, you can highlight sections of the code and use the F9 button.

    Indenting
    Inside of several structures, like loops, it is important that you indent the code properly. This not only for correct syntax, but also makes for easier reading. To make sure code is indented in the right way, simply highlight the code and type Ctrl + I.

    Example 1

    For this example, you could run these commands one at a time at the >> in the Command Window, but we will create a script M-file in the Editor, which we open by typing edit and hitting return or you can click on the “new script” button clipboard_ec012a794b1d60753cb3a60e4c0c72eaf.png. Enter the following commands on separate lines:

    SideLength = sqrt(5)
    Value = cos(pi)
    DegValue = cosd(180)
    radius = 5;
    Area = pi * radius ∧ 2

    Now save the file as test.m. To run the file you have the options listed in this chapter, but another easy way is to go to the Command Window and type
    test at the >> line. The output for this file should look like:

    SideLength =
    2.2361
    Value =
    -1
    DegValue =
    -1
    Area =
    78.5398

    Note that there was no output of the value for radius to the Command Window (the semicolon suppresses the output), but the value was stored in the variable named radius (and can be found in the Workspace window - look!).


    This page titled 1.6: Editor Tips 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.