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 Ansichten (letzte 30 Tage)
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. 
 

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 29 Mär. 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:

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by