No BSD License  

Highlights from
functionsclass

5.0

5.0 | 1 rating Rate this file 2 Downloads (last 30 days) File Size: 9.73 KB File ID: #2069

functionsclass

by Mihai Moldovan

 

05 Aug 2002 (Updated 05 Aug 2002)

A class that exposes MATLAB subfunctions as public methods of the primary functions.

| Watch this File

File Information
Description

The initial MATLAB programming model assumed that each function is in a separate file. When the programs became more complex the 'subfunctions' were introduced. The idea was that subfunctions are helper functions that can't be accessed from outside the primary function file. This paradigm changed again with the GUIDE implementation. The callbacks in the *.fig file are passed to the primary function in the *.m file that distributes them to the subfunctions using a 'FEVAL switchyard'.

What's next?

My idea is to consider a more 'object oriented' programming model. Objects are supported by MATLAB but their practical use is shaded by the complexity of implementation (How many examples have you seen so far ?!).

When looking at function files like objects, the subfunctions are methods of the primary functions.
In this case subfunctions became generally available from outside their function files. Something like:

argout=somefunction.somesubfunction(argin1, argin2, ...);

I implemented this mechanism in a 'functionsclass' object. To use it SIMPLY type:

f=functionsclass;
argout=f.somefunction.somesubfunction(argin1, argin2, ...);
argout=f.somefunction(argin1, argin2, ...);

As you might expect, the first call to a function/subfunction by this mechanism is somewhat slower than a normal MATLAB call. However, the functionclass object implements a 'Cache' property to store the called function handles so subsequent calls to the same functions are much faster.

The implementation is done only with *.m files and is highly commented (see tutorial.m) . You will discover how to implement a class with a 'ByRef' property in MATLAB. I mean ... the recommended property change in MATLAB is 'ByVal':
f=set (f,'Cache',[]);

But in this example you can simply write
set (f,'Cache',[]);

If you feel that MATLAB may evolve in this way PLEASE LET ME KNOW. If not... consider this just an advanced tutorial on MATLAB objects, subfunctions and function handles.

MATLAB release MATLAB 6.1 (R12.1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
17 Sep 2003 Felix Totir

Nice work; unfortunately, at the moment, the Matlab Compiler does not support objects.
I expect great improvements in R14 on objects: variable reference transfer etc.
I also intend to implement a "component" class (i.e. with events, methods, properties)

But, as I said, nice work; I'm gonna use it soon.

19 Apr 2005 mehdi jdir

i like to learn about an oriented object in matlab. how to make a class in m-file and how to call them in my programm?

17 May 2006 john baldwinson

Mihia
I like the concepts in functionsclass.

Is the class compatible with 2006a & 2006b matlab releases?
Please reply on my email

cheers
john

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
path Mihai Moldovan 22 Oct 2008 06:46:56
directories Mihai Moldovan 22 Oct 2008 06:46:56
files Mihai Moldovan 22 Oct 2008 06:46:56
byref Mihai Moldovan 22 Oct 2008 06:46:56
tutorial Mihai Moldovan 22 Oct 2008 06:46:56
classes Mihai Moldovan 22 Oct 2008 06:46:56
objects Mihai Moldovan 22 Oct 2008 06:46:56
subfunctions Mihai Moldovan 22 Oct 2008 06:46:56
function handles Mihai Moldovan 22 Oct 2008 06:46:56

Contact us at files@mathworks.com