(Parte 9 de 16)

4 , - A ffiqA1,a_J---*= "LvI x

<, lh jl':- ?l 5t

Izt -+Z] X+


At any point in a session, a list of all current variables can be obtained by entering the v;ho command:

> > rvho

Your yariabl es .rrc: al ans b x or. with more detail. cnter thc whos command: >;.whos fJ d r{ie A dns l)

Sr ze lx3 I x5 LX L 5xi '1 xl

Byte:: Class 12 clouble array 40 cloubLa array 8 tlouLr Lc: ;.Lrr ay 4Ct il,trrb l e i)i I'ay

I6 doubLe arr.r.y (comfiLex)

Clrancl t-otal is 21 elenrrrnl.s; LrsinqJ 175 bytes

Note that subscript notation can be used to access an individual elcment of an array. For exarnple. the firurth element o['thc column vccfor t) can be displayed as

:> b(4)

,tlt si . 8

Foranarray,A(nr ,n) selectslheclemcntinmthrowandthcnthcolurnn.Forexample, A(:,1)

Thsre are sevcral built-in functions that can be used 1o creatc matrices. For cxarnplc, the ones llnd zero:i l'unctions creatc vcctol's or matrices filled with ones and zeros. respectively. Both have two argumcnts, thc first tbr the nulnber of rows and the second tbr thc number-of columns. For example. to creatc a 2 x 3 matrix tl1'zeros:

E : 7,cI os; (2. , -) J

Sintilarly, the or-res fLtnction can be used to create a row vector of oncs:

u = onc::; (j, -l )

2.2.3 The Colon Operotor

The colon opefator is a powerfll tool fbr crerting and used to separate tw'o nunrbers, MATLAB generales lhe manipulating arrays. If a colon is numbers bclween lhem usinu an z$4 I Y ffial -

;n-Zt* 5t s-i LvI

<, [h - t('€ - ?'' 5lzf Ll 2 '|-Azl' -+IZ] X+

26 MATLAB FUNDAMENTALS l.J increment of one: -: l- - 1.(

If colons are used to separate three numbers. MAILAB generates the numbers between the first and third numbers using an increment equal to the second number:

>> t = L:0.5:3

1.0 1.5000 2.0 Note that negative increments can also be used

>-" f = i0:-1:5 t0 9 B 1 6 5

Aside from creating series of numbers, the colon can also be used as a wildcard to select the individual rows and columns of a matrix. When a colon is used in place of a specific subscript, the colon reprcsents the entire row or column. For example, the second row of the matrix A can be selected as in

>> A(2,:)

We can also use the colon notation to selectively extract a series of elements from within an array. For example, based on the previous definition of the vector t :

>>' 1- (2:4)

981 Thus, the second through the fourth elements are returned.

2.2.4 The rlnspace ond losspace Functions

The iinspacre and logspace functions provide other handy tools to generate vectors of spaced points. The 1 inspace function generates a row vector ofequally spaced points. It has the form

I inspace ( xl . x2 , n) which generates n points between xl and x2. For example

'> linspace(0,1,6)

0 0.2000 0.4000 0.6000 o.BOOO 1.0 lf the n is omitted, the function alromatically generates 100 points.

The logspace l-unction generates a row vector that is logarithmically equally spaced. It has the form logspace(x1, x2, n)

Ifn whi For


Res' plv thes ing


2.5000 3.0 2.3 rnr ope com

Th AS ffi=

Ll 2. * Zl eNst

J -tlh 3l"LvI x

?l -+ZI X+?2- =$8

2.3 MATHEMATICAL OPERATIONS27 which generates n logarithmically equally spaced points between For examp)e,

>> logspac e (-I ,2 , 4)

(Parte 9 de 16)