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 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 29 Mar 2018
Risposto: MathWorks Support Team
il 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.
Risposta accettata
MathWorks Support Team
il 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Structures in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!