Declare function for specific matlab versions
Mostrar comentarios más antiguos
vecnorm was introduced in R2017b. To ensure compatibility with previous versions I'd like to conditionally declare my own vecnorm function, based on the Matlab version, e.g. only declare it for versions less than R2017b.
Ideally, I'd like to call the function with its actual name, e.g. vecnorm. Also, I would like to not have to make any modifications at the site of the caller.
How can I achieve this in Matlab?
Respuestas (1)
Guillaume
el 3 de Oct. de 2018
0 votos
You have several options
Option 1 is to use verLessThan. Have your code call a stub vecnormstub function in which you perform the version check, if version is R2017b or later the stub calls vecnorm otherwise it calls your own implementation (which would have a different name). The main issue with this approach is finding the actual version numbers to give to verLessThan since Mathworks doesn't actually document them.
Option 2 is to use try catch. Have your code wrap the call to vecnorm into a try catch. If the catch triggers, and the exception is MATLAB:UndefinedFunction, call your own implementation (which again would have a different name). If the exception is not MATLAB:UndefinedFunction, rethrow
Option 3, if on <R2017b you want your implementation to be available even outside of your own code, is to put your function in a folder that you only add to the path if the version is <R2017b (again check with verLessThan).
Categorías
Más información sobre Linear Algebra en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!