Skip to main content
Engineering LibreTexts

1.3: Command Window Examples

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

    Let’s try some basic examples in the command window. Enter 5+5 in the command window (and press Enter)

    >> 5+5
    ans =
    10

    The value 10 has been assigned to the variable ans. Next, try the following

    >>a=5+5
    a=
    10
    >>b=5+5; % the semicolon suppresses output.

    A few things to note. First, assignment of values to the variables is right to left (whatever is on the right of the equals sign is assigned to the variable on the left). Here, both both a and b are equal to 10, but only a’s value is displayed because the semicolon is used to suppress the output to the screen. This is a very useful tool in programs where, for example, you want to hide the intermediate calculations.

    While there are thousands of commands in Matlab, here are a few that you will use often:

    clc clears the command window
    clear all clears all the variables
    clear variablename clears the variable named variablename
    close all closes all open plot windows
    ctrl + c stops a running process (important later!)

    There are several rules about the naming of variables (look those up in Help or Google), but in particular, all variable names must start with a letter and all variables are case sensitive (upper case and lower case letters are considered different)!! So, for example, the variables Math and math are treated as different variables.

    One final “peculiar” aspect of Matlab, is that you can only edit the line you are on!! You can however recall previous commands with the up and down arrow keys, or type text and use the up and down arrow keys to scroll through the commands starting with that text.


    This page titled 1.3: Command Window Examples 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.