The Command Window in MATLAB is where most of your programming outputs are displayed. The Command Window can be easily identified as the MATLAB environment subwindow with the “Command Window” label and a input prompt symbol “>>”. Figure 1 shows our default location of the Command Window as laid out in lesson [LINK TO LESSON].
We saw examples of outputs in the “Hello World” lesson. We can also program directly into the Command Window; however, our code will not be saved in an m-file. This means you can quickly test a few lines of code, use it like a calculator, or check the value of a variable (see Figure 2). This also means it can be a useful tool when debugging (find problems) in your program.
In many cases, we will want to stop some variables from being displayed in the Command Window. This is commonly called “suppressing” variables. Suppressing variables can decrease the run time of our program (if it is long) and also make it easier for us to see the outputs we are interested in.
To suppress a line of code in MATLAB, place a semicolon (;) at the end of the line. As seen in Example 1, only the variable a shows up in the Command Window because we suppressed the output of variable b with a semicolon at the end of the statement.
Important Note: Suppressing a line of code will only change whether it outputs to the Command Window or not: it does not stop MATLAB from performing the operation.
a = 2 %Creating an unsuppressed variable b = 3; %Creating an suppressed variable (note the semicolon) c = a*b; %There is no Command Window output from this line because we suppressed it. c %Demonstrating that “c” has been set to a*b (suppressing only stops the display output!). %Note, if you are confused by which line is displaying “c = 6” in the Command Window Output below, %you should rerun this code yourself and unsuppress all outputs. It should be immediately clear %what is happening.Command Window Output
a = 2 c = 6 [Try this code yourself with Octave Online! Click Here]
The difference between them is that help contains a summary of the documentation and displays directly in the Command Window (see Figure 3) while doc opens a new window with the full documentation page from MathWorks, which you can also see by clicking the links in here in the lesson text. Both are quick and easy ways to review documentation.
In the next lesson, we will cover how to use the Command Window effectively.