A Brief Introduction to MATLAB
There are two types of environments in which the MATLAB application
can be used:
Windows Interface:
If you are using MATLAB on a Mac, in PC Windows, or the X Windows
System under UNIX, you can start MATLAB by double clicking on the
MATLAB icon. A blank notebook page will be opened into which you
can enter your MATLAB commands.
MATLAB commands are executed as soon as the Enter (Return) key is pressed.
Multiple commands may be entered on a line by separating the commands with semi-colons (;).
When you first start MATLAB, three panes will open by default:
- The largest pane fills the right side of the window.
When this pane is selected, the File, Edit, Debug, Desktop, Window,
and Help menus are available at the top of the screen to assist you in
performing operations within MATLAB.
- The tabs at the bottom of the upper left pane enable you to select a display of the contents of the current
workspace or currently selected directory.
When the Workspace tab is selected in this pane, the File, Edit, View, Graphics, Debug, Desktop, Window,
and Help menus are available at the top of the screen to assist you in
performing operations within MATLAB;
when the Directory tab is selected in this pane, the File, Edit, View, Debug, Desktop, Window,
and Help menus are available at the top of the screen.
- The bottom left pane displays a history of commands that had previously been entered.
You can re-invoke a previously entered command by double clicking on it in the command history pane.
When this pane is selected, the File, Edit, Debug, Desktop, Window,
and Help menus are available at the top of the screen to assist you in
performing operations within MATLAB.
Note: You can access the "Help" menu from each of the above panes to obtain assistance
in using MATLAB and view example demos for its toolboxes.
Command line interface:
On Unix systems, you can start MATLAB in batch mode from the command line.
To start MATLAB in this mode, enter matlab at a system prompt. After the
MATLAB kernel loads, some messages will be displayed, and the ">>" prompt will appear indicating
that MATLAB has started and is waiting for you to enter commands.
HELP
If you are using a Windows based environment, you can obtain assistance
using the Help menu included at the top of the MATLAB window.
For example, a full listing of the available MATLAB functions can be viewed by opening
the "Help" menu at the top of the screen, selecting "Full Product Family Help", and then selecting "Functions -
Alphabetical List".
In addition to containing information
about MATLAB commands, the "Help" menu also provides tutorials to help you get started using the program.
Internal help can be obtained by entering the command "help" followed by the name of the function for which you
would like assistance; for example, to obtain infomation on the sin function, enter: help sin
SYNTAX
MATLAB is case sensitive (e.g., "a" is different from "A").
You can assign a value to a variable by typing the variable name followed by an equal sign and the value
you wish to assing to it, and then pressing the Enter (Return) key. The "value" can be a number, the name of
another variable, or a function specification.
When you enter the name of a defined variable or function whose variables are defined, the value of the variable
or function will be displayed. If you enter the name of an undefined variable, an error message will be
displayed indicating the value of the specified variable is not defined.
Use parentheses to specify the order of calculations, otherwise the default order of precedence
the most commonly use mathematical operators is:
Raise to a power x^2 e.g., 250000 is 2.5 10^5
Negation -x
Divide x/y
Multiply x*y
Addition x+y
Spaces can be used for readability between numbers, variables, and
functions, but are not required between operators and variable names.
Thus the product of x and y can be written as "x*y" or "x * y".
Multiple MATLAB statements can be included on the same line by
separating statements from one another with semicolons, e.g.:
x=4; y=6; w=7; z=x*y+w
To suppress the output display, include a semicolon at the end of a
line, e.g., "z=x*y+w;" above.
Comments
The percent (%) character is used to begin an inline comment.
To begin a block of comments, use the percent sign followed by a left curly brace (%{);
to end the block of comments, use the percent sign followed by a right curly brace (%})
USAGE
You can now type in MATLAB commands or equations. For example if
you enter "2*3+5" as a command, MATLAB will display the following result:
ans =
11
You can assign a value to a variable by entering the variable name
followed by an equal sign and a numeric value or function, e.g.:
a = 2*3+5
z = x / y
To remove a definition assigned to a variable or function, enter: clear(x) where "x" is the name of the variable
or function you which to deassign. It is recommended that one deassign variables once you no
longer need them.
SAVING Stored Values
The Save Command can be used to save values of variables and functions
to a file. For example, to save previous definitions of x and y in the
file "filename", enter: Save["filename",x,y]
You can retrieve values saved in "filename" by entering:
<<filename
SYSTEM COMMANDS Within MATLAB
To issue a command to the operating system from within the MATLAB
environment, precede the system command with an exclamation point (!),
e.g., in the UNIX environment, to issue the ls command to list files in
the current directory, enter: !ls
EXITing from MATLAB
To exit from MATLAB, select Exit from the File menu of a Windows
based environment; in command line environments, enter the MATLAB command "quit".
References
Information about the full MATLAB product line is available on the MATLAB web site:
http://www.mathworks.com
MATLAB documentation can be accessed as:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.html
|