Enhanced Matlab Plotting Series: Part IV

During the last post we extended mPlot formatting to axes and figure objects.  This post we are going to add some helper methods to the mPlot class.  Recall back in the second post of this series we added several methods for interfacing with the plotCounter variable.  While these methods did not do anything magical, they were extremely helpful and made interaction with the class easier.  The methods that we are going to add this time will allow easy access to current line settings, such as marker size or marker type.

Methods to Add

After using this class for some time, I found myself continually altering specific properties within the mPlot class.  While this worked, keeping track of the plotCounter indexing (to ensure modifications were to the current line settings) was a hassle.  Hence methods to interface with these properties made sense.   The methods we are going to add this time will be 1) setCurrentMarkerType, 2) setCurrentMarkerSize, 3) setCurrentLineStyle and 4) setCurrentMarkerEdgeColor.  As the name of each of these methods suggests, they will change some property of the current line.

The Code

The code for these 4 methods is pretty straightforward.  Once again, the content is nothing spectacular, but incorporates handy features that you will come to use.  Notice we’ve added a new methods block to the class.  This is not required (the code could be added to any methods block with the desired scope) but a useful habit for bundling methods designed to perform similar tasks.

…..take a minute and study the above code.  Some error trapping checks were put in place to ensure that the input arguments are valid marker types and line styles.  Other than these lines, most of the methods could be reduced to one-liners.

Example Using Methods

Lets work through an example to demonstrate some uses for this newly added functionality.

Imagine we have 3 different filters that are of interest.  We would like to display the magnitude response of each filter for several different filter orders.  Suppose we are testing filter orders of 10, 20 and 30 and we want the markers to be circles, squares and triangles, respectively.  So our marker type will reflect the filter order and the marker/line color will be indicative of filter type.  The code below should get the job done.

I’ve outlined several sections of the code in red.  This is the code that handles the plotting.  The other sections are merely constructing filter coefficients and evaluating the magnitude response of the filters.  The code produces the result below.

Notice that each marker reflects a particular filter order….as we intended.

Next Time

The other methods that we’ve added could be explored in more detail; but for now the above example demonstrates the functionality in a practical form.  So after 4 parts to this series we have constructed a framework for our plotting class and fleshed out an amount of functionality.  Stay tuned for more!


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s