How to overload a function with arguments of class sym?

3 次查看(过去 30 天)
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.

回答(0 个)

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by