How can I define a wrapper function to call a built in function such that the wrapper function has the same name as the built-in function?
13 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2018-3-29
回答: MathWorks Support Team
2018-4-3
How can I define a wrapper function to call a built in function such that the wrapper function has the same name as the built-in function?
For example, when I call "xlswrite", I want it to call a custom function, perhaps some routine, then call the builtin "xlswrite" function. I want to call the function "xlswrite" so I do not need to modify all my existing code.
采纳的回答
MathWorks Support Team
2018-3-29
You can utilize the "builtin" function to call the MATLAB built-in "xlswrite" from your overloaded "xlswrite" function. Your "xlswrite" will probably have a format as below:
function [success,theMessage]=xlswrite(file,data,sheet,range) % same structure as built-in "xlswrite"
% do the pre-processing
data = ...;
% call the MATLAB built-in "xlsread"
builtin('xlswrite', file, data, sheet, range);
end
Following is the documentation link for the "builtin" function that you can refer to:
Using this function will result in warning messages, since you are shadowing the MATLAB built-in "xlswrite" function. If you want to turn the warning messages off, you can execute the following commands at the MATLAB Command Window:
warning('off','MATLAB:dispatcher:nameConflict');
On the other hand, to turn the warnings on execute:
warning('on','MATLAB:dispatcher:nameConflict');
Following is the documentation link for "warning" function:
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!