This document provides an introduction to basic MATLAB commands and operations. It discusses how to enter and exit MATLAB, lists some common commands like clearing the screen and workspace. It also covers defining different variable types like scalars, vectors, matrices, and character arrays. It provides examples of arithmetic operations on arrays and defines matrices. Exercises are included to practice these concepts.
4. Entering & Quitting MATLAB
• To enter MATLAB double click on the MATLAB icon.
• To Leave MATLAB Simply type quit and press enter.
4
5. Some Basic Commands
• To check the list of installed toolboxes type
• To clear the screen type
• To move the cursor to upper left corner of the command window type
5
6. Some Basic Commands (contd…)
• To list the current variables type
• To list the current variables in long form type
• To clear the workspace type
• To remove particular variable from the workspace type
6
7. Some Basic Commands (contd…)
• To get list of Help topics type
• To get help for any topic type
• To get help for any command type
7
8. Some Basic Commands (contd…)
• To search command type
• To list the files in a directory type
• To list the Matlab files only type
8
10. Types of MATLAB Variables
• Scalar
array
• Vector
(column vector) or (row vector)
• Matrix
• Character Arrays (Strings)
10
11. Defining Scalars
Variables are assigned numerical values by
typing the expression directly, for example,
typing
yields:
11
12. Variable Definitions
We can also assign numerical values to the variables
by typing the expression
yields:
12
13. Variable Definitions
• After typing the expressions the answers are
echoed back.
• To suppress the echo put semicolon at the end
of the expression.
13
15. Variable Definition (Contd…….)
A variable can be assigned using a formula. For example,
since a was defined previously, the following expression is
valid
yields:
15
38. Exercise#6
1) Define a matrix A of dimension 2 x 4 whose (i,j) entry is A(i,j)=i+j
2) Extract two 2 x 2 matrices A1 and A2 out of the matrix A. A1 contains the
first two columns of A, A2 contains the last two columns of A
3) Compute the matrix B to be the sum of A1 and A2
4) Compute the eigen values and eigen vectors of B
5) Compute the determinant of B
6) Compute the inverse of B
7) Compute the rank of B
39. Defining Character Arrays (Strings)
39
Character arrays are created using single quote delimiter
1 2 3 4 5 6
41. Conversion B/W Numeric & String Arrays
• To convert from numeric to string array
– num2str
• To convert from string array to numeric array
– str2num
41