12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Inline objects, like every other matlab construction, is vectorised:>> f(0:4)ans =-1 0 38 15They can be used in place <strong>of</strong> other variables:x = linspace(-4,4);clfplt(x,f(x))hold onplt(x,f(x-2),’--’)zeroaxesExercise 10 Create a function called funplot that takes thename <strong>of</strong> a function <strong>and</strong> a range <strong>of</strong> x-values <strong>and</strong> produces a plotover that range. For example, the following input should producethis plot:funplot(’sin’,[0pi])The function should work whether you type funplot(’sin’,[0pi]) or funplot(’sin(x)’,[0 pi]). Hint: What are the asciivalues <strong>of</strong> ( <strong>and</strong> )? (Answer on page 188.)27 Cell ArraysCell arrays are arrays <strong>of</strong> different things. The “things” can be scalars,vectors, matrices, strings (<strong>of</strong> different length), structures (see section onstructures), or other cell arrays. For example, when we looked at stringmatrices we saw that we had to pad the rows with blanks to make themall the same length. Using a cell array, we can create a “ragged-rightmatrix”:t = {’O sacred receptacle <strong>of</strong> my joys,’;’Sweet cell <strong>of</strong> virtue <strong>and</strong> nobility,’;’How many sons <strong>of</strong> mine hast thou in store,’;’That thou wilt never render to me more!’}The curly brackets { <strong>and</strong> } denote cells. The cell we created above is a4 × 1 cell array:c○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!