lecture20

Uploaded from authorPOINTLite
Views:
 
Category: Entertainment
     
 

Presentation Description

No description available.

Comments

Presentation Transcript

Section 13.2 Handle Graphics: 

Section 13.2 Handle Graphics A handle is a “nickname” given to an object in MATLAB We can assign a handle to Individual plots The figure window The axis on which we draw the plots

Slide2: 

“Tree” structure Figure Axes User Interfaces Annotation axes Core Objects Group Objects Plot Objects MATLAB uses a hierarchical system for organizing plotting information

Slide3: 

Figure Axes User Interfaces Annotation axes Core Objects Group Objects Plot Objects The basic plotting object is the figure. The figure can contain a number of different objects

Slide4: 

Figure Axes User Interfaces Annotation axes Core Objects Group Objects Plot Objects The basic plotting object is the figure. The figure can contain a number of different objects

Slide5: 

Figure Axes User Interfaces Annotation axes Core Objects Group Objects Plot Objects The axes are contained inside the figure. Think of the axes as being layered on top of the figure window . The axes also can contain a number of different objects .

Slide6: 

Figure Axes User Interfaces Annotation axes Core Objects Group Objects Plot Objects The axes are contained inside the figure. Think of the axes as being layered on top of the figure window . The axes also can contain a number of different objects .

Slide7: 

Figure Axes User Interfaces Annotation axes Core Objects Group Objects Plot Objects A plot is drawn on top of the axes.

Anatomy of a graph: 

Anatomy of a graph Figure Axes layered on top of the figure Plot drawn on the axes

When you use a plot function…: 

When you use a plot function… MATLAB automatically creates a figure an appropriate axis draws the graph (plot) on the axis MATLAB uses default values for many of the plot object properties. For example the first line drawn is always blue, unless the user specifically changes it.

How to Change Default Actions: 

How to Change Default Actions some defaults can be modified with the plot() function >> xVals=linspace(0,pi,100); >> yVals=exp(sin(xVals)); compare >> plot(xVals, yVals); with >> plot(xVals, yVals,’r’);

Handles Allow us to Change (nearly) anything about the plot: 

Handles Allow us to Change (nearly) anything about the plot font & size of title font & size of labels style of tick-marks figure heading

Slide12: 

Figure Axes User Interfaces Annotation axes Core Objects Group Objects Plot Objects Each of these has a handle figure handle axes handle plot handle

Figure Handles: 

Figure Handles We can specify a handle name for the figure window Using the figure handle, we can change the figure title, background color, etc

Slide14: 

A figure window has a lot of properties

Slide15: 

If we haven’t specified a handle name, we can ask MATLAB to determine the current figure with the gcf command (get current figure) get(f_handle) and get(gcf) return the same results in this example

try these commands: 

try these commands gCounts = [10 9 8 7 2] pie(gCounts, {'A' 'B' 'C' 'D' 'F'}) get(gcf) set(gcf,'Color','red') set(gcf,'Color', [1 0 1]) add a name to your figure set(gcf,’name’,…)

generate a plot to work with using the plot() command: 

generate a plot to work with using the plot() command xVals=linspace(0,pi,100); yVals=exp(sin(xVals)); plot(xVals, yVals); look at the parent & children of the figure get(gcf) get(gcf,'children')

Axis Handles: 

Axis Handles Just as we can assign a handle to the figure window and the plot itself, we can assign a handle to the axis using the gca function (get current axis ) for example h_axis = gca

Slide19: 

h_axis is the name of the axis upon which the plot is drawn in this example

Annotation Axes: 

Annotation Axes In addition there is a transparent layer added to the plot, used for annotation objects, such as: lines legends text boxes

Plot Handles: 

Plot Handles Assigning a plot a name (or a handle) allows us to easily ask MATLAB to list the plot object properties

Slide22: 

h is the plot handle

Slide23: 

The get function returns a list of the object (in this case a plot) properties

summary: 

summary get() -- obtain information about a handle-graphics object set() -- change something about a handle-graphics object parent and children show the tree-structure of objects

Exercise: 

Exercise plot sin(x) for x= 0 to 3 pi Use bold fonts for the title and axis Increase the size of the font for the title by 2 points

Slide27: 

handle graphics Modify fonts for titles & labels set() discovers all the options for setting things about the axis get(handle) obtains the current settings gca is the handle of the current axes gcf is the handle of the current figure tree structure (gca is a child of gcf, the plot is a child of gca).

Slide28: 

Preditor-Prey Population Modeling Competition/cooperation between a preditor and prey Lotka-Volterra model Matrix Model Implementation

Slide29: 

Variables

Slide30: 

Lotka-Volterra Equation

Slide31: 

Approximate the solution to the LV model using Matlab

Slide32: 

Include a phase diagram

Slide33: 

Hint Instead of letting ode45() generate the plot, capture the solution and plot it yourself [Tvec critterVec] = ode45(@lvRHS, tVals, critters0); Cvec = critterVec(:,1); Pvec = critterVec(:,2); plot(Cvec,Pvec)

Slide34: 

Connection with handle graphices Change the line thickness of the graphs generated automatically by ode45 Use bold (and larger) fonts for the title. Use bold fonts for the legends and labels.