How to overload a function with arguments of class sym?
Show older comments
How can I create an overloaded function of type sym, for use by the symbolic tool box?
I can do this for double and char, by creating the functions in @double and @char subdirectories, but this doesn't seem to work for @sym. For example:
@char/myfunc.m:
function p = myfunc(x)
p = 'char arg';
end
@double/myfunc.m:
function p = myfunc(x)
p = 'double arg';
end
@sym/myfunc.m:
function p = myfunc(x)
p = 'sym arg';
end
Running which -all seems to find it:
>> which -all myfunc()
C:\Users\me\MATLAB\@char\myfunc.m % char method
C:\Users\me\MATLAB\@double\myfunc.m % double method
C:\Users\me\MATLAB\@sym\myfunc.m % sym method
But not when called with the corresponding argument:
>>which myfunc(1234)
C:\Users\me\MATLAB\@double\myfunc.m % double method
>> which myfunc('1234')
C:\Users\me\MATLAB\@char\myfunc.m % char method
>> which myfunc(sym(0))
'myfunc(sym(0))' not found.
>>class(sym(0))
ans =
'sym'
Any ideas? Thanks.
Answers (0)
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!