Skip to main content
Library homepage
 
Engineering LibreTexts

1.2.1: Clearing the Workspace, Readability Tips

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

      Clearing the workspace

      Generally, it's a good idea to use the following code when starting a MATLAB session or script file:

      format compact; % Don't insert blank lines on the console--saves screen space

      clear all; % Remove all previously defined variables

      close all; % Close all plots (figures)

      clc; % Clear the console (screen)

      Readability

      This example shows that you don’t have to put in spaces between numbers and operators, but spaces help readability. Try these two expressions:

      1+2+3+4+5+6

      1 + 2 + 3 + 4 + 5 + 6

      Both expressions give the same answer.

      These other arithmetic operators are clear:
      2*3 - 4/5
      2 raised to the 8th power is entered with the ^ symbol, called “caret”
      2^8
      The algebra order of operations is applied in MATLAB instructions.
      Use parentheses when you need a different order of operations.
      Parentheses can help readability even when not required.
      2*(3-4)/5


      This page titled 1.2.1: Clearing the Workspace, Readability Tips is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Carey Smith.