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 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 29 Mar 2018
Réponse apportée : MathWorks Support Team
le 3 Avr 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.
Réponse acceptée
MathWorks Support Team
le 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!