Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Managing files when extending built-in classes

Subject: Managing files when extending built-in classes

From: Dimitri Shvorob

Date: 12 Jul, 2008 13:14:02

Message: 1 of 6

.. Suppose I want to add a method to the built-in dataset-
array class. I can add a file to

C:\Program Files\MATLAB\R2007a\toolbox\stats\@dataset

folder, but the problem is, if I operate a file repository
(e.g., with Subversion), I need to add the built-in path to
the repo.

Is it possible to place 'extension'-method files outside of
the Matlab directory?

Thank you.


1. I don't think it's possible.
2. Why not just extend the built-in class? The not-quite-
inheritance of Matlab 2007 is a hassle, but it looks like
even that doesn't work: when I set up derived
class 'mydataset'

 function[obj] = mydataset(varargin)

 obj = dataset(varargin{:})

 class(obj)

 obj = class(struct([]),'mydataset',obj);

an attempt to instantiate a mydataset object fails:


>> z = rand(4,2); d = mydataset({z,'a','b'})

obj =

    a b
    0.48679 0.50851
    0.43586 0.51077
    0.44678 0.81763
    0.30635 0.79483


ans =

dataset

??? Error using ==> class
Base Object for class mydataset constructor is not valid.

Error in ==> mydataset.mydataset at 8
obj = class(struct([]),'mydataset',obj);


Subject: Managing files when extending built-in classes

From: Donn Shull

Date: 12 Jul, 2008 17:22:01

Message: 2 of 6

Hi Dimitri,

I don't know when the change happened but from at least
R2007a and later dataset used the new MATLAB object style
which was formally introduced in R2008a. You can't mix the
new and old styles when creating subclasses. In R2007a and
beyond you can create a subclass of dataset with the
following code in mydataset.m:

classdef mydataset < dataset
end

look at the documentation for R2008a Object Programming
more information on this.

Subject: Managing files when extending built-in classes

From: Kenneth Eaton

Date: 12 Jul, 2008 17:43:01

Message: 3 of 6

"Dimitri Shvorob" <not.dimitri.shvorob@gmail.com> wrote in
message <g5aamq$h8l$1@fred.mathworks.com>...
> .. Suppose I want to add a method to the built-in dataset-
> array class. I can add a file to
>
> C:\Program Files\MATLAB\R2007a\toolbox\stats\@dataset
>
> folder, but the problem is, if I operate a file
repository
> (e.g., with Subversion), I need to add the built-in path
to
> the repo.
>
> Is it possible to place 'extension'-method files outside
of
> the Matlab directory?
>
> Thank you.

I don't know if this is the case for newer versions of
MATLAB, but I thought that new methods for a built-in class
could be defined by making another directory (i.e.
@dataset) somewhere else on the MATLAB path and putting the
new methods there. I think MATLAB collects methods from all
the different directories.

Ken

Subject: Managing files when extending built-in classes

From: Dimitri Shvorob

Date: 12 Jul, 2008 18:28:01

Message: 4 of 6

> In R2007a and
> beyond you can create a subclass of dataset with the
> following code in mydataset.m:
>
> classdef mydataset < dataset
> end
>

WHAAA? I CAN USE THE NEW OOP FEATURES IN MATLAB 2007?!!
It seems so: the 'classdef' definition worked! (No, 'help
classdef' returned nothing). I feel silly but very excited.
Does anybody know what 2008 features are *not* there,
hidden, in Matlab 2007?

Thanks a lot, Donn!




Subject: Managing files when extending built-in classes

From: Loren Shure

Date: 14 Jul, 2008 12:26:59

Message: 5 of 6

In article <g5aqf5$h43$1@fred.mathworks.com>,
Kenneth.dot.Eaton@cchmc.dot.org says...
> "Dimitri Shvorob" <not.dimitri.shvorob@gmail.com> wrote in
> message <g5aamq$h8l$1@fred.mathworks.com>...
> > .. Suppose I want to add a method to the built-in dataset-
> > array class. I can add a file to
> >
> > C:\Program Files\MATLAB\R2007a\toolbox\stats\@dataset
> >
> > folder, but the problem is, if I operate a file
> repository
> > (e.g., with Subversion), I need to add the built-in path
> to
> > the repo.
> >
> > Is it possible to place 'extension'-method files outside
> of
> > the Matlab directory?
> >
> > Thank you.
>
> I don't know if this is the case for newer versions of
> MATLAB, but I thought that new methods for a built-in class
> could be defined by making another directory (i.e.
> @dataset) somewhere else on the MATLAB path and putting the
> new methods there. I think MATLAB collects methods from all
> the different directories.
>
> Ken
>

That's true for objects built on the older OO spec in MATLAB. The new
one, in R2008a, requires you to co-locate all methods. If that's not
possible, a viable option is subclassing. If you don't need access to
the innards of the class, you can also just write a function.

--
Loren
http://blogs.mathworks.com/loren/

Subject: Managing files when extending built-in classes

From: Kenneth Eaton

Date: 14 Jul, 2008 16:11:03

Message: 6 of 6

Loren Shure <loren@mathworks.com> wrote in message
> > I don't know if this is the case for newer versions of
> > MATLAB, but I thought that new methods for a built-in
class
> > could be defined by making another directory (i.e.
> > @dataset) somewhere else on the MATLAB path and putting
the
> > new methods there. I think MATLAB collects methods from
all
> > the different directories.
> >
> > Ken
> >
>
> That's true for objects built on the older OO spec in
MATLAB. The new
> one, in R2008a, requires you to co-locate all methods.
If that's not
> possible, a viable option is subclassing. If you don't
need access to
> the innards of the class, you can also just write a
function.
>
> --
> Loren
> http://blogs.mathworks.com/loren/

Good to know for when I eventually upgrade to R2008a.

Thanks,
Ken

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
class method inheritance Dimitri Shvorob 12 Jul, 2008 09:15:10
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics