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 views (last 30 days)
Show older comments
MathWorks Support Team
on 29 Mar 2018
Answered: MathWorks Support Team
on 3 Apr 2018
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.
Accepted Answer
MathWorks Support Team
on 29 Mar 2018
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 Comments
More Answers (0)
See Also
Categories
Find more on Structures 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!