**Lab 01: Introduction to MATLAB**

(Based on Matlab Manual)

**What is MATLAB?**

The name **MATLAB** stands for "**MAT**rix **LAB**oratory" and was originally designed as a tool for doing numerical computations with matrices and vectors. It has since grown into a high-performance language for technical computing. MATLAB, integrating computation, visualization, and programming in an easy-to-use environment, allows easy matrix manipulation, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages. Typical uses include:

- Math and Computation
- Modeling and Simulation
- Data Analysis and Visualization
- Application Development
- Graphical User Interface development

**Getting Started**

**Window Layout**

MATLAB development IDE can be launched from the icon created on the desktop. The main working window in MATLAB is called the desktop. When MATLAB is started, the desktop appears in its default layout:

The following tools are managed by MATLAB desktop, although not all of them appear by default when you first start

**Current Folder**- This panel allows you to access the project folders and files.**Command Window**- This is the main area where commands can be entered at the command line.It is indicated by the command prompt (**>>**).**Workspace**- The workspace shows all the variables created and/or imported from files.**Command History**- This panel shows or rerun commands that are entered at the command line.

By default, the **Command History** window closes after a statement is selected or the **Esc** key is pressed. To keep the **Command History** window open, in the **Command History** window, click and then select either **Detach** or **Dock.** If the **Command History** window is closed while detached or docked, go to the **Home** tab, and in the **Environment** section, click **Layout**. Then, under **Show**, click **Command History** and select either **Docked** or **Popup**.

## Variables

MATLAB does not require a command to declare variable. A variable is created simply by directly allocating a value to it. All variables are created with double precision unless specified and they are matrices.

>> **v = 3**

v =

3

After these statements, the variables are 1x1 matrices with double precision.

>> **23 + 18** # no declarations needed

ans =

41

>> **product = 18 * 32.64** # mixed data type

product =

5.875200000000000e+02

>> **product = 18 * 555.24;** # semi-colon suppresses output of calculation's result

>> **product**

product =

9.994320000000000e+03

**MATLAB Variable Names**

- Variable names are
**CASE SENSITIVE**. - Variable names can contain up to
**63**characters (as of MATLAB 6.5 and newer). - Variable names must
**start with a letter**followed by**letters**.**digits**, and**underscores**(**_**). - MATLAB has several
**keywords**that cannot be used as programmer-defined variable names.

The following table provides a list of keywords. The list of keywords can be found by entering the command "iskeyword" on the Command Window.

break |
case |
catch |
classdef |
continue |

else |
elseif |
end |
for |
function |

global |
if |
otherwise |
parfor |
persisyent |

return |
spmd |
switch |
try |
while |

**Special Variables and Constants**

Command |
Description |

ans |
Temporary variable containing the most recent answer. If you do not assign an output variable to an expression, MATLAB automatically stores the result in .ans |

eps |
This variable name is short for “epsilon”. It is the smallest difference between two numbers that can be represented on the computer. (Smallest incremental number) |

i, j |
The imaginary unit |

inf |
Infinity. Calculations like , where n/0 is any non-zero real value, result in n.inf |

NaN |
Not-a-Number, indicates an undefined numerical result. Expressions like and inf/inf result in a 0/0, as do arithmetic operations involving a NaN. NaN, where n/0 is complex, also returns n.NaN |

pi |
The number ( = 3.1415926535897...) |

realmin |
The smallest usable positive real number. |

realmax |
The largest usable positive real number. |

computer |
Computer type. |

version |
MATLAB version string. |

clock |
This special variable contains the current date and time in the form of a 6-element row vector containing the year, month, day, hour, minute, and second. |

date |
Contains the current data in a character string format, such as .24-Nov-1998 |

Here are several examples that use these values in MATLAB expressions.

>> **x = 2 * pi;**

>> **A = [3+2i 7-8i];**

>> **tol = 3 * eps;**