15.11.2014 Views

Chapter 4: Programming in Matlab - College of the Redwoods

Chapter 4: Programming in Matlab - College of the Redwoods

Chapter 4: Programming in Matlab - College of the Redwoods

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Section 4.6 Nested Functions <strong>in</strong> <strong>Matlab</strong> 429<br />

i. Set both ‘XLim’ and ‘YLim’ properties to [−10, 10].<br />

ii. Set both ‘XTick’ and ‘YTick’ properties to -10:2:10.<br />

iii. Set both ‘XGrid’ and ‘YGrid’ properties to ‘on’.<br />

Create three panels. One panel will hold an edit box where <strong>the</strong> user enters his<br />

equation, a second will hold edit boxes for <strong>the</strong> w<strong>in</strong>dow parameters xm<strong>in</strong>, xmax,<br />

xscl, ym<strong>in</strong>, ymax, and yscl. You might also want to create an edit box <strong>in</strong> this second<br />

panel that conta<strong>in</strong>s <strong>the</strong> number <strong>of</strong> po<strong>in</strong>ts to be plotted. Should a graph have a<br />

“jagged” appearance, <strong>in</strong>creas<strong>in</strong>g <strong>the</strong> number <strong>in</strong> this edit box would smoo<strong>the</strong>n <strong>the</strong><br />

graph. A third panel should conta<strong>in</strong> a uicontrol that is a pushbutton. This pushbutton<br />

should have its ‘Str<strong>in</strong>g’ property set to ‘Graph’ and ‘Callback’ property<br />

set to <strong>the</strong> handle @plotFunction_Callback.<br />

The design should allow <strong>the</strong> user to enter his equation, w<strong>in</strong>dow parameters, and<br />

number <strong>of</strong> po<strong>in</strong>ts. When <strong>the</strong> user clicks <strong>the</strong> pushbutton with his mouse, <strong>the</strong><br />

callback function plotFunction_Callback will grab <strong>the</strong> w<strong>in</strong>dow parameter data<br />

and adjust ‘Xlim’, ‘YLim’, ‘XTick’, and ‘YTick’ <strong>of</strong> <strong>the</strong> axes object accord<strong>in</strong>gly.<br />

Then <strong>the</strong> user’s equation should be drawn over <strong>the</strong> doma<strong>in</strong> [Xm<strong>in</strong>,Xmax].<br />

This problem could potentially be expanded <strong>in</strong>to a semester end<strong>in</strong>g project,<br />

add<strong>in</strong>g ‘Zoom’ menu or a ‘Calc’ menu for f<strong>in</strong>d<strong>in</strong>g zeros and extrema. This project<br />

is very open-ended with lots <strong>of</strong> potential for fur<strong>the</strong>r implementation <strong>of</strong> ideas and<br />

utilities.

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

Saved successfully!

Ooh no, something went wrong!