Thread Subject: OO Programming: Differences between @-folder and classdef-file usage

Subject: OO Programming: Differences between @-folder and classdef-file usage

From: M

Date: 18 Mar, 2010 13:48:05

Message: 1 of 4

I want to merge some procedural Matlab code to OO-Code.

I first started with creating and @-folder and have accomplished in writing a simple contructor and subsref method (both working as expected). The class is an aggregation of objects of the same kind from another class A and some extra parameters.

Now I found out that it is also possible to define a class in a single file with a classdef-block. I would prefer to do it that way. So I copied the code form the class-folder to the classdef-file. But now when creating an object of the class I get an object that contains the parameters as expected, but the cell array that should contain the objects of class A containse also cell arrays that contain cellarrays ....

My question is: Why does Matlab has these two ways in defining a class and what are the differences.

Subject: OO Programming: Differences between @-folder and classdef-file usage

From: Matt J

Date: 18 Mar, 2010 15:41:05

Message: 2 of 4

"M " <aflopb-mat@yahoo.de> wrote in message <hntaul$2p5$1@fred.mathworks.com>...
> I want to merge some procedural Matlab code to OO-Code.
>
> I first started with creating and @-folder and have accomplished in writing a simple contructor and subsref method (both working as expected). The class is an aggregation of objects of the same kind from another class A and some extra parameters.
>
> Now I found out that it is also possible to define a class in a single file with a classdef-block. I would prefer to do it that way. So I copied the code form the class-folder to the classdef-file. But now when creating an object of the class I get an object that contains the parameters as expected, but the cell array that should contain the objects of class A containse also cell arrays that contain cellarrays ....
>
> My question is: Why does Matlab has these two ways in defining a class and what are the differences.
=========

The two methods exist because the one using @-directories was the former way and has been replaced in later MATLAB editions by classdef files. @-directories are still available for backward compatibility.

Note also that the @-directory and classdef file approaches are not mutually exclusive. You can define a class using classdef inside a @-directory. This allows you to put class methods in separate files if you wish to.

The classdef approach has a lot of new capabilities over the old style. There are many differences between the two approaches but none of them, I don't think, explain the problem you are describing. To understand that, we would need to see actual code/examples.

Subject: OO Programming: Differences between @-folder and classdef-file usage

From: Steven Lord

Date: 18 Mar, 2010 17:27:35

Message: 3 of 4


"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message
news:hnthih$3c5$1@fred.mathworks.com...
> "M " <aflopb-mat@yahoo.de> wrote in message
> <hntaul$2p5$1@fred.mathworks.com>...
>> I want to merge some procedural Matlab code to OO-Code.
>>
>> I first started with creating and @-folder and have accomplished in
>> writing a simple contructor and subsref method (both working as
>> expected). The class is an aggregation of objects of the same kind from
>> another class A and some extra parameters.
>>
>> Now I found out that it is also possible to define a class in a single
>> file with a classdef-block. I would prefer to do it that way. So I copied
>> the code form the class-folder to the classdef-file. But now when
>> creating an object of the class I get an object that contains the
>> parameters as expected, but the cell array that should contain the
>> objects of class A containse also cell arrays that contain cellarrays
>> ....
>>
>> My question is: Why does Matlab has these two ways in defining a class
>> and what are the differences.
> =========
>
> The two methods exist because the one using @-directories was the former
> way and has been replaced in later MATLAB editions by classdef files.
> @-directories are still available for backward compatibility.
> Note also that the @-directory and classdef file approaches are not
> mutually exclusive. You can define a class using classdef inside a
> @-directory. This allows you to put class methods in separate files if you
> wish to.
>
> The classdef approach has a lot of new capabilities over the old style.
> There are many differences between the two approaches but none of them, I
> don't think, explain the problem you are describing. To understand that,
> we would need to see actual code/examples.

M,

The Object-Oriented Programming section in the User Guide chapter of the
MATLAB documentation contains a subsection that briefly describes how the
new classdef-based syntax differs from the old non-classdef-based syntax.

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brqzfth-1.html

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: OO Programming: Differences between @-folder and classdef-file usage

From: M

Date: 22 Mar, 2010 17:15:22

Message: 4 of 4

Thank you both!

The hint with 'not mutually exclusive' will surely help to keep track of the code.

And well - sometimes I am just looking at the wrong places in the Documentation.

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
object oriented M 18 Mar, 2010 09:49:10
oo M 18 Mar, 2010 09:49:10
rssFeed for this Thread

Contact us at files@mathworks.com