File Exchange Pick of the Week

July 7th, 2008

Advanced MATLAB: Class system for OOP in MATLAB introduction

This week we will be looking at the MATLAB class system. This video does not cover the “why” of doing OOP (Object Oriented Programming) in MATLAB. It just covers a very simple example of doing OOP.

The ten minute video shows an implementation of Conway’s Game of Life in MATLAB with classes. Though it is not covered in the video, you can implement other lifelike Cellular Automation algorithms by altering the parameters for survival and birth.

iconFiles.jpgiconPod.jpg

3 Responses to “Advanced MATLAB: Class system for OOP in MATLAB introduction”

  1. J.Paul R replied on :

    Nice, but there seems to be a bug in the included files. On line 19 you look for a (presumed) property countSelf, which doesn’t exist. Adding countSelf = false; (or countSelf=true;) in the property section fixes this.

    For an alternative implementation, see:
    http://blogs.mathworks.com/steve/2008/05/20/lookup-tables-conway-game-life/

    Steve used binary lookup tables and the image processing toolbox for a “vectorized” approach which would presumably be faster.

  2. Doug replied on :

    Thank you. I must have “cleaned up” my code accidentally. Problem has been solved and updated in the File Exchange!

    Doug

  3. DanK replied on :

    Doug,
    A very nice and timely blog, since I’m just starting the learning of MatLab OOP this week. I would like to mention one glaring hole in the documentation, etc. which is that there are virtually no examples of classes where the methods are not contained in the classdef file. The project which I’m now applying OOP to has something like 30 subfunctions with about 8,000 lines of code, so I don’t want to try to stick it all in one monster file. Likewise I was most unsatisfied with the documentation on packages. Overall, I think it will take me a while to get used to thinking in OOP, but I see potential benefits, and this blog did provide some help in terms of a framework.

    Thanks,
    Dan

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • oleg: The author has implemented skewness, kurtosis and checks answering appropriately to the critic.
  • Ashok: how to store 10 or more random number in a loop a loop for i = 1:n mean(i) = input(’enter the mean value...
  • Ben: Doug, Thanks for the very helpful videos! Uitables seem like a convenient way to make a customized property...
  • oleg: Allstats has no checks, no comments and could also be improved (talking about prctile implementatio). Not to...
  • Todd: Additional information and a link to download free MATLAB and Simulink LEGO MINDSTORMS NXT code can be found at...
  • Doug: @Leo, Here is the “English version” of that code. “vec = []” makes an empty variable...
  • leo: Dear Doug I have a question in your code ‘October 9th, 2009 at 13:53′ vec = []; vec = [vec val]; I...
  • Shanker Keshavdas: You sir, are a gentleman and a scholar… No really, helped me out a lot. As to what is...
  • Quan Zheng: how can I get a copy of stepspecs.m?
  • Doug: @Lucy I think this is what you seek to move a line with the mouse in MATLAB. http://blogs.math...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.