An Introduction to MATLAB

MATLAB is a environment for scientific computing that is ideal for computations that require extensive use of arrays and graphical analysis of data.

Matlab basics

To start Matlab on the University of Maryland's glue network and perform some basic operations, try

:~: tap matlab :~: matlab < M A T L A B > Copyright 1984-2001 The MathWorks, Inc. Version 6.1.0.450 Release 12.1 May 18 2001 To get started, type one of these: helpwin, helpdesk, or demo. For product information, type tour or visit www.mathworks.com. >> >> % this is a comment >>

where :~: is the unix shell prompt and >> is the MATLAB environment prompt. At this point, MATLAB is ready to begin a computational session. Hitting the return key generates a MATLAB prompt on a new line; we will make extensive use of MATLAB comments which are found after the % character.

MATLAB and the file system

It is important to understand the relationship between the MATLAB operating environment and your computer's file system stucture because

Try the following commands on your computer:

>> pwd % present working directory >> ls % list directory contents >> mkdir newdir % make a new directory (folder) named newdir >> cd newdir % change directories to newdir

Data types

The default data type in MATLAB is a double-precision array. While this data type tends to be used most often in computations, several other data types also are important:

>> a = 2 % a scalar double a = 2 >> b = [ 2, 3] % a 1 by 2 array b = 2 3 >> s = 'a character string' s = a character string >> c = {'elements', 'in a cell array', 2} c = 'elements' 'in a cell array' [2] >> t.a = 1 t = a: 1 >> t.b = 'a structure' t = a: 1 b: 'a structure' >> class(t) % returns the data type ans = struct

Arrays

Arrays are defined and accessed based on the following concepts: