LECTURE 1
Ing. Kelcise Vidal Sesay, BEng (Hons)
An Introduction to MATLAB
MATLAB, developed by The MathWorks, Inc., integrates computation,
The MATLAB Desktop Start button The Start button in the bottom left corner of the MATLAB Desktop allows you to start up demos, tools, and other windows not present when you start MATLAB. Try Start: MATLAB: Demos and run one of the demos from the MATLAB Demo window.
Command window
MATLAB expressions and statements are evaluated as you type them in the
Command window, and results of the computation are displayed there too. Expressions and statements are also used in M-files. They are usually of the form:
variable = expression
or simply:
expression
Expressions are usually composed from operators, functions, and variable names. Evaluation of the expression produces a matrix (or other data type), which is then displayed on the screen or assigned to a variable for future use. If
the variable name and = sign are omitted, a variable ans (for answer) is
automatically created to which the result is assigned. A statement is normally terminated at the end of the line. However, a
statement can be continued to the next line with three periods (...) at the
end of the line. Several statements can be placed on a single line separated by commas or semicolons. If the last character of a statement is a semicolon, display of the result is suppressed, but the assignment is carried out. This is essential in suppressing unwanted display of intermediate results.
EXAMPLE
Matrices can also be constructed from other matrices. If A is the 3-by-3 matrix shown above, then:
You can save the Command window dialog with the diary command: diary filename This causes what appears subsequently in the Command window to be written to the named file (if the filename is omitted, it is written to a default file
named diary) until you type the command diary off; the command diary on
causes writing to the file to resume.
The format of the displayed output can be controlled by the following commands:
format short format long format short e format long e format short g format long g fixed point, 5 digits fixed point, 15 digits scientific notation, 5 digits scientific notation, 15 digits fixed or floating-point, 5 digits fixed or floating-point, 15 digits
format short is the default. Once invoked, the chosen format remains in effect until changed. These commands only modify the display, not the
Workspace window
The Workspace window lists variables that you have either entered or computed in your MATLAB session. There are many fundamental data types (or classes) in MATLAB, each one a multidimensional array. The classes that we will concern ourselves with most are rectangular
The command who (or whos) lists the variables currently in the workspace. A variable or function can be cleared from the workspace with the command
Command History window This window lists the commands typed in so far. You can re-execute a command from this window by double-clicking or dragging the command
Current Directory window Your current directory is where MATLAB looks for your M-files, and for workspace (.mat) files that you load and save. You can also load and save matrices as ASCII files and edit them with your favorite text editor. The file should consist of a rectangular array of just the numeric matrix entries.
Array Editor window Once an array exists, it can be modified with the Array Editor, which acts like a spreadsheet for matrices. Go to the Workspace window and double-click on the matrix C.
Click on an entry in C and change it, and try changing the size of C. Go back
THE END