Professional Documents
Culture Documents
Variable
Explorer
Command Window
Command
History
4
Undocking a Window
Click ‘Undock’ button on frame to undock the window
Current Directory is
undocked in its
own window
5
Docking a Window
Click ‘Dock’
button on frame
to dock the
window.
6
Configuring the Matlab Desktop
7
Main Screen (Command Prompt)
Command prompt.
(Note: MATLAB still supports its command
interpreter language and you still can write
scripts. This region of the screen allows you to
launch the scripts, the script editor, and models.)
help help
8
Help Function
9
Navigating Help Topics
• There is a help entry for each toolbox installed. The
following partial list is an example.
matlab\general - General purpose commands.
matlab\ops - Operators and special characters.
matlab\lang - Programming language constructs.
matlab\elmat - Elementary matrices and matrix manipulation.
matlab\elfun - Elementary math functions.
matlab\specfun - Specialized math functions.
matlab\matfun - Matrix functions - numerical linear algebra.
matlab\datafun - Data analysis and Fourier transforms.
matlab\polyfun - Interpolation and polynomials.
matlab\funfun - Function functions and ODE solvers.
matlab\sparfun - Sparse matrices.
matlab\scribe - Annotation and Plot Editing.
11
Anatomy of a Help Topic Entry
• Type “help quit”. The following should appear
Standard format
QUIT Quit MATLAB session.
QUIT terminates MATLAB after running the script FINISH.M,
if it exists. The workspace information will not be saved Command description
unless FINISH.M calls SAVE. If an error occurs while
executing FINISH.M, quitting is cancelled.
Example
Put the following lines of code in your FINISH.M file to Command usage
display a dialog that allows you to cancel quitting.
12
HTML Formatted Help Topic Entry
13
Matlab ‘WHICH’ function
14
Command Punctuation
15
Iteration
A matrix is a 2
dimensional array
C-Code Equivalent
(matrix) // The loop goes while x < 10, and x
//increases by one every loop
for ( int x = 0; x < 11; x++ ) {
// Keep in mind that the loop condition
A vector is a 1 dimensional array. // checks the conditional statement
// before it loops again. Consequently,
// when x equals 10 the loop breaks.
// x is updated before the condition is
// checked.
cout << x <<endl;
}
C-Code Equivalent
float A[11];
float B[11];
• This usually takes the form of “do while” or “do until”. (This typically happens when a
set of calculations may need to be repeated until a set of conditions are true.)
• In MATLAB you have the while statement which repeats a set of statements an
indefinite number of times. The general form of a while statement is:
while (expr rop expr )
statements
end
• The statements are executed while the real part of the expression has all non-zero
elements. The expression is usually the result of expr rop expr where rop is {==, <, >,
<=, >=, or ~=}.
• The BREAK statement can be used to terminate the loop prematurely.
• For example (assuming A already defined):
A=[1 2 3; 4 5 6; 7 8 9];
E = 1.*A; Example of infinite loop and the use of ^c
F = E + eye(size(E));
N = 1;
while norm(E+F-E,1) > 0,
E = E + F;
F = A*F/N;
N = N + 1;
end
20
Arithmatic Operators
21
Matrix Operators Example
a a a a
a ' 11 21 where, a 11 12
a12 a22 a21 a22
a b a b a b a b
ab 11 11 12 21 11 12 12 22
a21b11 a22b21 a21b12 a22b22
a11 a12 b11 b12
where, a and b b b
21 22
a a 21 22
Observe that
x A1b
where
1 1 2 x1
A 3 1 1 x x2
1 3 4 x3
2
and b 6
4
23
Array Operation Example
24
Matlab Cell Arrays - Example
Voltage Current
Experiment ID Measurements Measurements
Calculated Resistances
Experimental Data
25
Matlab Structures - Example
26
File I/O - Reading data from Excel
• Given the following Excel spreadsheet, read the data into the
Matlab workspace. (The spread sheet contains both numerical and
text data.)
27
File I/O - Reading data from delimited text files
28
File I/O - Reading data from comma delimited text
files
Given the following comma delimited text, read the data into
the Matlab workspace. (The text file contains numerical
data only.)
29