# MATLAB Development environment

 Getting Started with MATLAB  Calculations at Command Line  Using MATLAB Functions  MATLAB Desktop Environment  Getting MATLAB Help

MATLAB Development Environment

Introduction - 2

Getting Started with MATLAB

MATLAB Development Environment Introduction .3 Getting Started with MATLAB .

MATLAB Development Environment Introduction .4 Quitting MATLAB  To end your MATLAB session. . select Exit MATLAB from the File menu in the desktop OR   Using the close button OR Type quit in the Command Window.

>> a ^ b ans = 32 >> x = 5/2*pi.547 Assigning Variables >> a = 2. >> b = 5.MATLAB Development Environment Introduction .1232e-017 >> exp ( acos (0.048821 >> ( 3 + 4 i ) * ( 3 ± 4 i ) ans = 25 >> cos (pi/2) ans = 6.3) ) ans = 3.5 Calculations at the command line MATLAB as a calculator >> -5 / ( 4. >> y = sin (x) y= 1 >> z = asin (y) z= Semicolon suppresses screen output Results assigned to ³ans´ if name not given Use parentheses ( ) for function inputs Numbers are stored in double-precision floating point format .32 ) ^ 2 ans = -0.8 + 5.

6 Executing a series of Commands .MATLAB Development Environment Introduction .

break % Terminate execution of current loop/file.hit any key to continue.MATLAB Development Environment Introduction . % Comments start with "%" character pause keyboard % Pause & return control to command line. return % Exit current function % Return to invoking function/command line. % Type "return" to continue.7 Script M-files    Standard ASCII text files Contain a series of MATLAB expressions (Typed as you would at the command line) Commands parsed & executed in order % Suspend execution . .

8 Script M-Files (Example)  Write a script file to generate first µn¶ elements of fibonacci series >> fibo enter the number of elements to be generated 8 1 1 2 3 5 8 13 21 .MATLAB Development Environment Introduction .

Creates a variable named z. or function is executing.MATLAB Development Environment Introduction .9 The MATLAB Workspace A statement like z = 10. and saves it in a part of computer memory known as the workspace. The MATLAB Command window and script files have a common workspace . M-file. A workspace is the collection of all the variables and arrays that can be used by MATLAB when a particular command. stores the value 10 in it.

>> who Your variables are abc >> clear c. >> who Your variables are ab clear clears all the variables from the workspace Clear variable_name clears the specified variable from the workspace . >> a = 10. >> b = 20.MATLAB Development Environment Introduction . >> c = a + b .10 The MATLAB Workspace To Clear a variable from the workspace the µclear¶ command can be used as shown below.

the workspace contains the following variables: >> whos Name Size Bytes Class area 1x1 8 double array radius 1x1 8 double array s 1x32 64 char array Grand total is 34 elements using 80 bytes >> who Your variables are: area radius s . after M-files calc_area is executed.MATLAB Development Environment Introduction . For example.11 The MATLAB Workspace A list of the variables and arrays in the current workspace can be generated with the whos and who commands.

12 Working with Files & Variables MATLAB Function Usage CD/PWD. WHOS SIZE Navigating directories Displays files in a directory (grouped by type) Invoke operating system Identifies the object referenced Remove function or variable from memory List workspace variables Returns the size of a matrix (rows and columns) .MATLAB Development Environment Introduction . DIR WHAT ! (bang) WHICH CLEAR WHO.

adplin.m Introduction .m wave.13 >> what M-files in the current directory C:\Program Files\MATLAB\R2007a adplin wave .. .MATLAB Development Environment some useful functions used often in MATLAB >> pwd ans = C:\Program Files\MATLAB\R2007a\work >> cd ('C:\Program Files\MATLAB\R2007a') >> pwd ans = C:\Program Files\MATLAB\R2007a >> dir M-files in the current directory .asv wave.

MATLAB Development Environment some useful functions used often in MATLAB >> which mean Introduction .14 C:\Program Files\MATLAB\R2007a\toolbox\matlab\datafun\mean.4 5 6] a= 1 4 >> size( a ) ans = 2 3 2 5 3 6 >> ndims(a) ans = 2 >> length(a) ans = 3 .m >> a=[1 2 3.

15 Array Editor For editing 2-D numeric arrays double-click >> openvar A .MATLAB Development Environment Introduction .

CD .. CD directory-spec sets the current directory to the one specified. Use the functional form of CD. moves to the directory above the current one. such as CD('directory-spec'). . prints out the current directory. See also PWD. when the directory specification is stored in a string.MATLAB Development Environment Introduction . CD. WD = CD returns the current directory as a string. by itself.16 Online Help   CD The help command The help window >> help >> helpwin >> help cd Change current working directory.

Bugs & Requests .17 More About Getting Help     The HELP command The help window MATLAB Documentation >> help >> helpwin The MATLAB Help Browser >> helpbrowser >> doc     Online Reference (HTML / PDF) Solution Search Engine Index / Contents Link to The Mathworks   FTP site & latest documentation Submit Questions.MATLAB Development Environment Introduction .

MATLAB Development Environment Introduction .18 Which Help Do I Use?    If there is a type (grouping) of functionality that you are looking for >> helpwin If you are looking for a specific functionality Help->Search->Full Text Search If you know the function name >> help function_name or >> doc function_name .

19 MATLAB Editor/Debugger >> edit %opens new file OR brings editor into focus >> edit <filename> %opens file named <filename> >> edit startup %opens the startup.MATLAB Development Environment Introduction .m file (shown) .

MATLAB Development Environment Introduction . the Profiler.20 Profiler MATLAB includes a graphical user interface. Type profile viewer to open the GUI Enter statement to profile Click Start . to help you improve the performance of your M-files.

MATLAB Development Environment Introduction .21 MATLAB Desktop MATLAB Current Directory MATLAB Help Window MATLAB Command History MATLAB Workspace .