Thread Subject: visibility of classdef subfunctions

Subject: visibility of classdef subfunctions

From: Matt

Date: 25 Nov, 2009 13:36:03

Message: 1 of 2

This issue came up in another thread, but it piqued my curiosity.

It seems that subfunctions in a classdef file are visible to class properties and methods, but for some reason they are not visible in the classdef Attributes block. I'm wondering if this is intentional or a bug.

EXAMPLE:

classdef myClass

   properties
     prop=initialize;
   end
   
   methods
       function out=myfunc(obj)
           out=initialize;
       end
   end
end

function out=initialize();%appears in myClass.m

  out=true;
 
end

%%%%%%%%

This works fine

>> clear classes; A=myClass; A.prop, A.myfunc,

ans =

     1


ans =

     1


However, if I add a class Attribute block

classdef (Sealed=initialize) myClass

then instantiating the class causes an error.
>> clear classes; A=myClass;
??? Error using ==> myClass
Error: File: myClass.m Line: 1 Column: 11
Undefined function or variable 'initialize'.

This problem goes away if I relocate initialize() to its own separate M-file, but I'm wondering why this would be necessary.

Subject: visibility of classdef subfunctions

From: Philip Borghesani

Date: 25 Nov, 2009 20:19:35

Message: 2 of 2

The initial reaction is that this is a bug. Further investigation will determine if it is fixable or will become a "feature"

Phil

"Matt " <xys@whatever.com> wrote in message news:hejbs3$jag$1@fred.mathworks.com...
> This issue came up in another thread, but it piqued my curiosity.
>
> It seems that subfunctions in a classdef file are visible to class properties and methods, but for some reason they are not
> visible in the classdef Attributes block. I'm wondering if this is intentional or a bug.
>
> EXAMPLE:
>
> classdef myClass
>
> properties
> prop=initialize;
> end
>
> methods
> function out=myfunc(obj)
> out=initialize;
> end
> end
> end
>
> function out=initialize();%appears in myClass.m
>
> out=true;
>
> end
>
> %%%%%%%%
>
> This works fine
>
>>> clear classes; A=myClass; A.prop, A.myfunc,
>
> ans =
>
> 1
>
>
> ans =
>
> 1
>
>
> However, if I add a class Attribute block
>
> classdef (Sealed=initialize) myClass
>
> then instantiating the class causes an error.
>>> clear classes; A=myClass;
> ??? Error using ==> myClass
> Error: File: myClass.m Line: 1 Column: 11
> Undefined function or variable 'initialize'.
>
> This problem goes away if I relocate initialize() to its own separate M-file, but I'm wondering why this would be necessary.
>

Tags for this Thread

Everyone's Tags:

oop

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
oop Matt J 25 Nov, 2009 08:39:19
rssFeed for this Thread

Contact us at files@mathworks.com