Is it possible to call a function that doesn't have precedence?

I am aware of Matlab's Function Precedence Order. It appears that the only way to call a function that isn't on the path, or has lower precedence on the path, is to change directories so that it has precedence.
However, I am trying to write a function, 'someFunc', that extends an older version of 'someFunc' (and is actually a protected .p file). Unfortunately, the original 'someFunc' indirectly calls itself (it calls another function which then calls it again). This means the technique of changing directories to call the original 'someFunc' won't work, since all recursive calls then call the original 'someFunc' not the new 'someFunc' (since it is in the current directory). Moreover, since 'someFunc' isn't directly recursive, I can't use a private function to override the precedence either.
I was hoping to use a function handle to call the original function instead of changing directories, but that doesn't work either, as outlined here.

 채택된 답변

Sean de Wolski
Sean de Wolski 2015년 6월 26일

2 개 추천

You could put it in a package and then import the package (import pack.somefunc) or call directly into the package (pack.somefunc()).

댓글 수: 3

Thanks!
Unfortunately this didn't work for me. As soon as I put the pcoded class in a package it quit working. My only guess is that the pcoded class isn't using classdef (as required), but I can't tell since it is protected and matlab doesn't give any other feedback other than "Undefined variable" when called as pkg.class or "Import argument 'pkg.class' cannot be found or cannot be imported.' when trying to import it.
However, I verified this would have worked if it was either a standalone function or a class created with classdef, so I am accepting this as the solution, since it will probably work 99% of the time.
You can learn more about your class by looking at metaclass() of it (also the ?)
mc = pkg.class
Then inspect mc to learn what the restrictions are.
Thanks for the tips.
Here's what happens:
>> mc = mypkg.myclass
Undefined variable "mypkg" or function "mypkg.myclass".
But I can do (where someF just prints SomeF):
>> mypkg.someF
SomeF
If I pull myclass out of +mypkg I can do:
>> metaclass(myclass)
Error in myclass(line 196)
Output argument "obj" (and maybe others) not assigned during call to "myclass".
>> ? myclass
ans =
0x0 class array with properties:
Name
Description
DetailedDescription
Hidden
Sealed
Abstract
Enumeration
ConstructOnLoad
HandleCompatible
InferiorClasses
ContainingPackage
PropertyList
MethodList
EventList
EnumerationMemberList
SuperclassList
Edit: If I call a valid constructor I get the same as the ?:
>> metaclass(myclass(correctargs))
ans =
0x0 class array with properties:
Name
Description
DetailedDescription
Hidden
Sealed
Abstract
Enumeration
ConstructOnLoad
HandleCompatible
InferiorClasses
ContainingPackage
PropertyList
MethodList
EventList
EnumerationMemberList
SuperclassList

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

질문:

2015년 6월 26일

편집:

2015년 6월 29일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by