You are on page 1of 6

MATLAB Environment

2.1 Getting Started 5^2 ans = 25 cos(pi) ans = -1 2.2 MATLAB Windows Middle: command window

9/28/2012 4:38:00 PM

Right: command history window & workspace windows Left: current folder window AUTO: Document windows, graphic windows & editing windows All undockable Menu>Desktop>Desktop Layout>Default 2.2.1 Command Window o Scratch pad: save values calculate, but NOT the commands used to generate those values. o Create M-FILE if need to save command sequences. 2.2.2 Command History o Command history records commands you issued. Command history remains despite exiting. o Allows you to transfer commands to the command window. o clc clears the contents of command window, but leaves history. 2.2.3 Workspace Window o Workspace window keeps track of VARIABLES you have defined as you execute commands in the command window. Ans, 25, 1x1, 8, double Grid symbol by ans means array 1x1 tells us it is a single value, & therefore scalar double = double precision floating point: can store a number with a decimal point. MATLAB considers every number to be a floating point number, whether or not youve inserted a decimal.

o A=5 A= 5 now A has been added as variable, with value 5. o Adding matrices: B = [1, 2, 3, 4] (commas are optional) B= 1 2 3 4 B has now been added as a variable: 1x4 matrices, 32 bytes Two dimensional matrices: C = [ 1 2 3 4; 10 20 30 40; 5 10 15 20] C= 1 2 3 4 10 20 30 40 5 10 15 20 C has now been added as a variable: 3x4 matrices, 96 bytes o Values may be easily recalled by typing in variable name. o o 2.2.4 o 2.2.5 o clear command clears workspace commands. whos command executes workspace variables & info Current Folder Window Lists all files in the active directory Document Window Double clicking variables in workspace launches a document window: VARIABLE EDITOR. Values are displayed in spreadsheet, so thus then are changeable in the array editor. May add new values.

o Placing SEMICOLON after the value suppresses output, so that it is not repeated in the command window. 2.2.6 Graphics Window o Launches when you request a graph. X = [1 2 3 4 5]; Y = [10 20 30 40 50]; PLOT(X,Y) *Window opens

Figure 1 2.2.7 Edit Window o FILE>NEW>SCRIPT: type and save a series of commands without executing them. o Alternate: type edit at the command prompt o Alternate: New Script button on the toolbar 2.2.8 Start Button o In newer versions. 2.3 Solving Problems with MATLAB 2.3.1 Using Variables o All names must start with letter. Only first 63 characters are used by MATLAB. o Use lowercase letters and numbers in variable names and capital letters for names of constants. o Speed of light is always lowercase c. o Names should be short enough to remember & descriptive o Characters: letters, numbers & underscore. o isvarname command to check whether var name allowed. Isvarname time Ans = 1 1 means true, 0 means false. iskeyword command causes MATLAB to list these reserved names. o If you override commands like, sin with sin = 4, be aware that sin no longer functions as sine. Fix this by Which sin Sin is a variable Clear sin Which sin Built-in . . . Practice exercise 2.2 Matrices in MATLAB Scalar = 1x1 matrix. List of values = column or row = 1D matrix = vector

o 2.3.2 o o

o o o o

A table of values = 2D matrix Matrix = Array with MATLAB users 1x2 is 1 row, 2 columns: 1y, 2x Scalar Operations A=1+2 a is assigned a value of 1 plus 2 B=5 X=A+B X= 8

= IS ASSIGNMENT OPERATOR. X=x+1 X= 9 o Order of Operations

9/28/2012 4:38:00 PM

9/28/2012 4:38:00 PM

You might also like