Enhanced Matlab Plotting Series: Part V

Last post we added several helper methods that allowed for easy interface with current line settings.  Think of that functionality as low-level relative to what we are going to discuss this post (by low-level I mean simple or core functionality).  The method we are going to add this time serves to provide much higher level functionality (higher level being more advanced and specific…but less reusable).  This new method is going to place the mPlot object into a state, with a specific behavior.  This will be similar to the auto-incrementing state that was discussed in a previous post in this series.

What will this state do?

The state we are going to cover today will deal with holding a particular marker and cycling through other line properties.  Similar to last time, this can come in handy when we need to compare multiple runs of an experiment, multiple filters/controllers or models, etc.

The basic layout

Before jumping directly into code, lets go through how this functionality should behave.  We want to enable this state and have our mPlot object 1) set and hold a particular marker style and 2) automatically increment through the other line properties as we feed data to the object via the plot method.  Once we disable this state 1) we want to move to the next set of unique line settings and 2) return auto-incrementing to its previous state (leave on if it was on and turn off if it was originally off).  Simple enough….time to code.

Coding Property Definitions

The code below shows definitions for the properties to be used.  These properties will allow use to enable and disable (via isHoldingMarkerStyle) holding a particular marker style (the heldMarkerStyle).  The private property isAutoIncrementingPreviousState will store the previous state of the objects auto-incrementing property.  The fact that this properties setAccess state is private means that users of an instantiated object can NOT change this property.

Property Set/Get Methods

With the isHoldingMarkerStyle property, we are going to take advantage of set/get methods for the property.  In short, this simply allows one to run a method (execute some function) when a property value changes.  Check out the code below.  We have performed some simple marker validation after enabling the state.  Notice near the bottom we have defined a new method for checking if a markerType is valid.

More details regarding set/get methods for properties can be found on the Matlab OOP documentation website at http://www.mathworks.com/help/techdoc/matlab_oop/brgsek9-1.html.

Implementing the functionality

Last but not least, we need to actually write the code to apply the marker of interest.  This will be performed inside of the plot call within the mPlot class.  In the code below, notice that we have added an intermediate variable named currentMarker.  This value is toggled to reflect the desired marker selection technique (default or current held marker).

Example of use

To test this functionality out, consider a situation where you need to overlay several model predictions with a measured data set.  In this case, we will draw the models with a line/no markers and the measured data with markers.

The code

produces the plot below.

Next Time

The functionality we added above focused on holding a particular marker type.  Similar behavior could be added for all of the line properties (line style, marker edge color, etc).  For the next set in this series we will add in other high level functionality.  Within the next couple of posts, we will diverge for a post and explain inheritance.  It will be tied into this series; we will use this functionality to help one personalize this class.  Let me know if you have any questions or comments.

This entry was posted in Matlab Plotting. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s