How do I invoke a shadowed core MATLAB function (not built-in) from an overloaded function of same name
Mostrar comentarios más antiguos
In an application I wanted to add a calling jacket for MATLAB's print. I was trying to add a print option -dsvg which used the great resource plot2svg.m to print to .svg, while using MATLAB's regular print for all other cases.
If I name my function print() in my local project folder, I can shadow the main print function for this application only, but I cannot then call base MATLAB print inside my custom version of print. I had thought
builtin('print' ...)
would do the trick, but print is not built-in so cannot be accessed in this way. I could use run command which changes directory but that seems "dodgy" (one would want to use try-catch to preserve directory in the case of print failure, at least). I could give my function a different name, but then I have to locate and change every call to "print" in my app, which is exactly what I was seeking to avoid!
Is there an nice way of doing this? Any help gratefully received.
Respuesta aceptada
Más respuestas (1)
Christopher Berry
el 14 de Ag. de 2014
Editada: Christopher Berry
el 14 de Ag. de 2014
Julian,
I think you had the right idea with the run command to call print, but use the fullpath instead of cd into the directory. You can also use matlabroot to keep your script portable as well:
printMatlab = fullfile(matlabroot,'toolbox','matlab','graphics','print.m');
run(printMatlab)
As long as the script (here just print) does not change the directory it is in, run will return to the correct working directory on success or failure, so you do not need to worry about using try-catch yourself.
3 comentarios
Julian
el 14 de Ag. de 2014
Christopher Berry
el 14 de Ag. de 2014
You are right, without arguments print is not all that useful. I was looking for a way around this when I saw your post.
Julian
el 14 de Ag. de 2014
Categorías
Más información sobre Debugging and Analysis en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!