Command Window
This is the primary interface for MATLAB's interpreter.
It is where commands are entered in order to be executed.
With octave, this is the only component.
Command History
This provides a history of all commands that were entered into
the Command Window, including from previous sessions. You may
click/drag past commands to re-execute them in the Command Window.
It is also possible to revisit past commands directly at the
Command Window prompt by using the up/down arrows.
Workspace
This provides a view of all currently defined variables during a
MATLAB session. For each variable it can display the name, the
data class, the array size, and the values. It is also possible
to edit an existing variable graphically by double clicking on
its name, invoking the spreadsheet-like Variable Editor.
Current Directory
Script and function m-files from the current directory can be
used directly from the command window. The current directory is
also relevant when saving and loading data.
x = value;
assigns the variable name x to whatever value is
expressed on the righthand side of the assignment operator (=).
If x had previously been defined, this assignment
reassigns the name to the new value.
If an expression is ever entered without an explicit assignment, the result will automatically be assigned the the variable ans.
By default, the result of each command is automatically echoed by MATLAB. To avoid that output, a command must be followed by a semicolon (;).
who
lists the names of all variables currently defined in the workspace.
whos
lists the names and associated data for all variables currently defined in the workspace.
clear x
removes the variable x from the current workspace.
clear
clears the workspace of all previously defined variables.
clc
visibly clears the command window (but leaves the underlying
workspace unchanged).
disp(x)
displays the value of x (but without displaying the variable name).
help x
prints informational text about x in the command window.
doc x
brings up the MATLAB documentation viewer with (typically) more extensive
information about topic x.
While the interactive Command Window is convenient, we do not always want to restart from scratch or to have to retype a long series of commands. We can save a series of commands in a text file that is traditionally known as an "m-file" in MATLAB lingo (because it is saved using a filename such as myproject.m).
The percent sign is used in MATLAB to designate the remainder of any line as a comment. This provides a convenient way for documenting portions of your source code. For example, you might write
gravity = 9.8; % measured in meters/second^2