Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Does which function work for user-defined classes?

Subject: Does which function work for user-defined classes?

From: Richard Crozier

Date: 6 Sep, 2013 12:37:06

Message: 1 of 11

On my system I try the example from the help doc for 'which'

>> which('serial/fopen')
C:\Program Files\MATLAB\R2012a\toolbox\matlab\iofun\@serial\fopen.m % serial method

great! works fine. However, if I try it on one of my own classes:

>> which('fpproc/fpproc')
'fpproc/fpproc' not found.

but which on just fpproc works as expected:

>> which fpproc
<snip>\fpproc.m % fpproc constructor

Is which.m broken for user classes, or am I misunderstanding the docs? This happens for me in both 7.14.0.739 (R2012a) 32 Bit and 8.0.0.783 (R2012b) 64 Bit on different machines.

Someone else also seems to be having trouble with which, but noone's answered:

https://www.mathworks.co.uk/matlabcentral/answers/55463-strange-output-from-which-for-class-definition-file-in-package

Subject: Does which function work for user-defined classes?

From: Steven_Lord

Date: 6 Sep, 2013 14:14:43

Message: 2 of 11



"Richard Crozier" <r.crozier@ed.ac.uk> wrote in message
news:l0ci9i$akc$1@newscl01ah.mathworks.com...
> On my system I try the example from the help doc for 'which'
>
>>> which('serial/fopen')
> C:\Program Files\MATLAB\R2012a\toolbox\matlab\iofun\@serial\fopen.m %
> serial method
>
> great! works fine. However, if I try it on one of my own classes:
>
>>> which('fpproc/fpproc')
> 'fpproc/fpproc' not found.
>
> but which on just fpproc works as expected:
>
>>> which fpproc
> <snip>\fpproc.m % fpproc constructor
>
> Is which.m broken for user classes, or am I misunderstanding the docs?
> This happens for me in both 7.14.0.739 (R2012a) 32 Bit and 8.0.0.783
> (R2012b) 64 Bit on different machines.

Is your fpproc file a MATLAB class implemented in a CLASSDEF file? If so try
this:

    which fpproc.fpproc

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Does which function work for user-defined classes?

From: Richard Crozier

Date: 6 Sep, 2013 14:33:16

Message: 3 of 11


>
> Is your fpproc file a MATLAB class implemented in a CLASSDEF file? If so try
> this:
>
> which fpproc.fpproc
>
> --
> Steve Lord

Hi Steve,

Yes fpproc uses classdef syntax, you can see the actual file here:

https://sourced.ecdf.ed.ac.uk/projects/see/xfemm/browser/trunk/mfemm/postproc/fpproc.m?rev=127

>> which fpproc.fpproc
'fpproc.fpproc' not found.

however which with this syntax does work for functions/classes in package directories, for instance I have an 'oandm' package (in directory +oandm) with a 'system' class:

>> which oandm.system
<snip>\+oandm\system.m % oandm.system constructor
>> which oandm.system/system
'oandm.system/system' not found.

Incidentally, is which.m meant to work for classes in packages? Admittedly packages are not mentioned in the help. With a built in Matlab class I picked at random none of the combinations:

>> which helpUtils.helpProcess
C:\Program Files\MATLAB\R2012a\toolbox\matlab\helptools\+helpUtils\@helpProcess\helpProcess.m % helpUtils.helpProcess constructor
>> which helpUtils.helpProcess/helpProcess
'helpUtils.helpProcess/helpProcess' not found.
>> which helpProcess/helpProcess
'helpProcess/helpProcess' not found.

works. Same result on both systems I mentioned previously.

Subject: Does which function work for user-defined classes?

From: Richard Crozier

Date: 6 Sep, 2013 14:38:10

Message: 4 of 11

To clarify this I did:

------ testclass.m ---------
classdef testclass < handle
    
    properties
        % nothing here!
    end
    
    methods
        
        function this = aclass()
            % do nothins
        end
        
    end
    
end
------ testclass.m ---------

>> which testclass
<snip>\testclass.m % testclass constructor
>> which testclass/testclass
'testclass/testclass' not found.

Subject: Does which function work for user-defined classes?

From: Richard Crozier

Date: 6 Sep, 2013 14:40:23

Message: 5 of 11

"Richard Crozier" wrote in message <l0cpci$87a$1@newscl01ah.mathworks.com>...
> To clarify this I did:
>
> ------ testclass.m ---------
> classdef testclass < handle
>
> properties
> % nothing here!
> end
>
> methods
>
> function this = aclass()
> % do nothins
> end
>
> end
>
> end
> ------ testclass.m ---------
>
> >> which testclass
> <snip>\testclass.m % testclass constructor
> >> which testclass/testclass
> 'testclass/testclass' not found.


oh and:

>> which testclass.testclass
'testclass.testclass' not found.

Subject: Does which function work for user-defined classes?

From: Steven_Lord

Date: 6 Sep, 2013 14:57:02

Message: 6 of 11



"Richard Crozier" <r.crozier@ed.ac.uk> wrote in message
news:l0cp3c$3o9$1@newscl01ah.mathworks.com...
>
>>
>> Is your fpproc file a MATLAB class implemented in a CLASSDEF file? If so
>> try this:
>>
>> which fpproc.fpproc
>>
>> --
>> Steve Lord
>
> Hi Steve,
> Yes fpproc uses classdef syntax, you can see the actual file here:
>
> https://sourced.ecdf.ed.ac.uk/projects/see/xfemm/browser/trunk/mfemm/postproc/fpproc.m?rev=127
>
>>> which fpproc.fpproc
> 'fpproc.fpproc' not found.
>
> however which with this syntax does work for functions/classes in package
> directories, for instance I have an 'oandm' package (in directory +oandm)
> with a 'system' class:
>
>>> which oandm.system
> <snip>\+oandm\system.m % oandm.system constructor
>>> which oandm.system/system
> 'oandm.system/system' not found.
>
> Incidentally, is which.m meant to work for classes in packages? Admittedly
> packages are not mentioned in the help. With a built in Matlab class I
> picked at random none of the combinations:
>
>>> which helpUtils.helpProcess
> C:\Program
> Files\MATLAB\R2012a\toolbox\matlab\helptools\+helpUtils\@helpProcess\helpProcess.m
> % helpUtils.helpProcess constructor
>>> which helpUtils.helpProcess/helpProcess
> 'helpUtils.helpProcess/helpProcess' not found.
>>> which helpProcess/helpProcess
> 'helpProcess/helpProcess' not found.
>
> works. Same result on both systems I mentioned previously.

I'm not certain off the top of my head why that's not working. Please
contact Technical Support and ask them to investigate this in more depth, as
this should be working. Once they determine why it wasn't working and how to
get it working, please ask them to enter an enhancement request for the
documentation staff to update the documentation for WHICH to include that
information.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Does which function work for user-defined classes?

From: Richard Crozier

Date: 6 Sep, 2013 15:07:06

Message: 7 of 11


> I'm not certain off the top of my head why that's not working. Please
> contact Technical Support and ask them to investigate this in more depth, as
> this should be working. Once they determine why it wasn't working and how to
> get it working, please ask them to enter an enhancement request for the
> documentation staff to update the documentation for WHICH to include that
> information.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Ok, thanks, I will contact technical support. It would be interesting to know if anyone out there (or you?) can reproduce this. As I'm trying on different computers with different versions of Matlab I tentatively suspect a genuine bug here.

Subject: Does which function work for user-defined classes?

From: Eric Sampson

Date: 6 Sep, 2013 15:47:10

Message: 8 of 11

"Richard Crozier" wrote in message <l0cr2q$66p$1@newscl01ah.mathworks.com>...
>
> > I'm not certain off the top of my head why that's not working. Please
> > contact Technical Support and ask them to investigate this in more depth, as
> > this should be working. Once they determine why it wasn't working and how to
> > get it working, please ask them to enter an enhancement request for the
> > documentation staff to update the documentation for WHICH to include that
> > information.
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > To contact Technical Support use the Contact Us link on
> > http://www.mathworks.com
>
> Ok, thanks, I will contact technical support. It would be interesting to know if anyone out there (or you?) can reproduce this. As I'm trying on different computers with different versions of Matlab I tentatively suspect a genuine bug here.

It seems to work OK for me on a user-written class on R2013a 64-bit Win7 x64, using the documented '/' syntax. The class in case isn't in a package though, if that matters.

Subject: Does which function work for user-defined classes?

From: Richard Crozier

Date: 6 Sep, 2013 19:41:16

Message: 9 of 11


>
> It seems to work OK for me on a user-written class on R2013a 64-bit Win7 x64, using the documented '/' syntax. The class in case isn't in a package though, if that matters.

hmm, ok, well either I'm doing something wrong, or this has been fixed in newer versions. Thanks for the info.

Subject: Does which function work for user-defined classes?

From: Richard Crozier

Date: 10 Sep, 2013 14:39:06

Message: 10 of 11

"Eric Sampson" wrote in message <l0ctdu$em8$1@newscl01ah.mathworks.com>...
> "Richard Crozier" wrote in message <l0cr2q$66p$1@newscl01ah.mathworks.com>...
> >
> > > I'm not certain off the top of my head why that's not working. Please
> > > contact Technical Support and ask them to investigate this in more depth, as
> > > this should be working. Once they determine why it wasn't working and how to
> > > get it working, please ask them to enter an enhancement request for the
> > > documentation staff to update the documentation for WHICH to include that
> > > information.
> > >
> > > --
> > > Steve Lord
> > > slord@mathworks.com
> > > To contact Technical Support use the Contact Us link on
> > > http://www.mathworks.com
> >
> > Ok, thanks, I will contact technical support. It would be interesting to know if anyone out there (or you?) can reproduce this. As I'm trying on different computers with different versions of Matlab I tentatively suspect a genuine bug here.
>
> It seems to work OK for me on a user-written class on R2013a 64-bit Win7 x64, using the documented '/' syntax. The class in case isn't in a package though, if that matters.

Well tech support have confirmed the issue to an extent saying:

"In general, methods are findable when the class is not loaded if and only if they are defined in separate files (in an @-directory) AND they are not in any packages. "

Subject: Does which function work for user-defined classes?

From: Eric Sampson

Date: 10 Sep, 2013 17:52:09

Message: 11 of 11

"Richard Crozier" wrote in message <l0naua$86b$1@newscl01ah.mathworks.com>...

>
> Well tech support have confirmed the issue to an extent saying:
>
> "In general, methods are findable when the class is not loaded if and only if they are defined in separate files (in an @-directory) AND they are not in any packages. "

That makes sense, when I tried it both of those conditions were true...

Tags for this Thread

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.

Contact us