ece220matlab - A Very Brief Introduction to Matlab by John...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: A Very Brief Introduction to Matlab by John Walsh, for ECE 220 Fall 2004 August 23, 2004 1 The Basics You can type normal mathematical operations into MATLAB as you would in an electronic calculator. Begin by typing 1+2 [Enter] , you should see EDU>> 1+3 ans = 4 Your display may not include the EDU before the prompt. This just indicates that you are using a version other than the student version of MATLAB. Other mathematical operations are just as simple as addition. For example, heres how to subtract two numbers EDU>> 1-2 ans =-1 Multiplication is naturally just as simple, as is handling non-integer numbers EDU>> 2.25*2 ans = 4.5000 To calculate a number to an exponent use the syntax EDU>> 2^2 ans = 4 The syntax for other binary operations implemented in MATLAB is shown in Table 1. Suppose we wish to to store the result of an operation so we can access it later. We can do this by assigning a variable name to the result of an operation, i.e. 1 MATLAB Expression Description x+y Add x and y. x-y Subtract y from x. x*y Multiply x and y. x/y Divide x by y. x y x to the yth power ( ) Parenthesis x= y Assign the value of y to x x == y Test to see if each elements of x and y are equal Table 1: Arithmetic Operations in MATLAB. EDU>> r=3*5; EDU>> s=2.2; EDU>> r*s ans = 33 Here, the variable names were r and s. Variable names consist of a letter, followed by any number of letters, digits, or underscores. MATLAB uses only the first 31 characters of a variable name. MATLAB is case sensitive; it distinguishes between uppercase and lowercase letters. A and a are not the same variable. To view the matrix assigned to any variable, simply enter the variable name. 1 Also, you should not pick variable names that are the same as the name of a function (to be discussed later). Notice we suppressed MATLABs output for the first two commands by including a semicolon (;) at the end of the command. Notice also that = here works differently from the usual mathematical notion of equality, instead it acts as an assignment operator. If you want to test whether or not two items are equal, you should use ==. MATLAB will return 1 if the two items are equal and 0 if they are not. EDU>> s==2.2 ans = EDU>> s==33 ans = 1 2 Vectors and Matrices in MATLAB MATLAB is built to naturally work with vectors and matrices (the former are a special case of the later with one of the two dimensions having length 1). To input a column vector into MATLAB, surround the vector you wish to input with brackets, and separate its elements with semicolons: 1 Quote from MATLAB documentation. 2 EDU>> v=[1 ; 2 ; 3 ; 4] v = 1 2 3 4 Row vectors are input in a similar manner, only the elements are separated by commas or spaces....
View Full Document

This note was uploaded on 02/10/2008 for the course ECE 2200 taught by Professor Johnson during the Fall '05 term at Cornell University (Engineering School).

Page1 / 16

ece220matlab - A Very Brief Introduction to Matlab by John...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online