MATLAB is a high-level technical computing language and interactive
environment for algorithm development, data visualization, data analysis,
and numeric computation.
The MATLAB system consists of the following parts:
A description of most of the commands and techniques for programming
can be found in the Getting Started with MATLAB Users' Guide. These
notes cover only a small number of these commands so if you wish to
expand your use of MATLAB you should obtain or have access to one of
the User's Guides.
MathWorks, MATLAB's vendor, maintains a web site with many links to online resources that will introduce you to the use of MATLAB. These resources include:
On Microsoft Windows machines, start the MATLAB program by
double-clicking the MATLAB shortcut on your Windows desktop.
On Apple Macintosh machines, start MATLAB by double-clicking the
MATLAB icon in the Applications folder.
On UNIX platforms, start MATLAB by typing matlab at the operating
system prompt.
When you start MATLAB, the desktop appears, containing tools (graphical user interfaces) for managing files, variables, and applications associated with MATLAB. The following illustration shows the default desktop with the Command Window panel on the right, the Workspace in the top left panel and the Command History in the bottom left panel.
You will type your commands in the Command Window. The output generated by a command (e.g. the result of a mathematical opearion) will also appear in the Command Window. The Workspace window will display a list with the names and values of all the variables you have defined, and the Command History window will display a complete record of all the commands you have typed.
Let us assign the value of 3 to a variable x by typing x=3 after the prompt >>. MATLAB echoes the variable assignment in the Command Window and updates the Workspace and Command History windows as shown in the following illustration.
Let us now assign the value of 4 to another variable y and issue the command z=x+y to compute the sum of x and y. Note that the use of a colon ; at the end of the command y=4 has suppressed the output (echo) of the assignment of variable y. The following illustration shows the result of the operation displayed in the Command Window and the updated Workspace and Command History windows.
You can customize the arrangement of tools and documents to suit your needs. In the following illustration, the current directory and its contents are displayed in the top left window instead of the Workspace.
To end your MATLAB session, select the File > Exit MATLAB menu option, or type quit in the Command Window.
1.4 Scalar Arithmetic Operators
Operation |
MATLAB Form |
|
---|---|---|
+ |
Addition |
a+b |
- |
Subtraction |
a-b |
* |
Multiplication |
a*b |
/ |
Right Division |
a/b |
\ |
Left Division |
a\b |
^ |
Exponentiation |
a^b |
MATLAB executes scalar operations with the following order of precedence:
Precedence |
Operation |
---|---|
First |
Parentheses: Evaluated starting with the innermost pair |
Second |
Exponentiation: Evaluated from left to right |
Third |
Multiplication and division with equal precedence: Evaluated from left to right |
Fourth |
Addition and subtraction with equal precedence: Evaluated from left to right |
Perform the following operations with MATLAB:
1.5 Getting Help
There are several ways to get help for MATLAB commands or functions.
In addition to giving you a way to find out about functions that are
not described in these notes or in the User's Guide, the help command will frequently show you new ways to use functions. Both the
developers of MATLAB and the authors of functions for your courses
frequently expand the scope of functions to make them more useful.
Get help for the following MATLAB commands: