inconsitent function overloading MATLAB R2017a
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I am currently encountering problems with function overloading within MATLAB R2017a.
I try to overload common functions such as abs and max among others. It seems to be simple but in fact for me it is not.
To do this, I create specific directories OVERLOAD\@single, OVERLOAD\@int32, OVERLOAD\@uint32 and OVERLOAD\@double. abs and max functions are redefined into @double and @single.
Overloaded abs function into @single is defined as: function [ output ] = abs(x) ...
overloaded max function is defined as: function [ output ] = max(varargin) ...
After adding path to OVERLOAD parent directory at ht beginning of path, I execute "which -all" command trying to understand which function is effectively called when executing abs and max. This is what I get:
>> which abs -all;
D:\Data\OVERLOAD\@single\abs.m % single method
D:\Data\OVERLOAD\@double\abs.m % double method
built-in (C:\Program Files\Matlab\R2017a\toolbox\matlab\elfun\@double\abs) % double method
...
>> which max -all;
built-in (C:\Program Files\Matlab\R2017a\toolbox\matlab\datafun\max)
D:\Data\OVERLOAD\@single\max.m % single method
D:\Data\OVERLOAD\@double\max.m % double method
...
It seems that overloading for max function appears in second position after built-in instead of first position.
Could anyone explain me why overloading is successful for abs and fails for max ?
Thanks for your attention.
6 个评论
Philip Borghesani
2018-11-15
Try
which max(single(1),single(1))
Or
which abs(single(1))
The default max takes multiple types but abs is overloaded for all numeric data types.
Jan
2018-11-16
@Didier Billard: We do not close this question, because it might help others with similar questions. Please post your "solution" as an answer and accept it to mark this thread as "solved". Even such "wrong questions" are very useful and valuable for this forum.
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!