Declare function for specific matlab versions

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?

답변 (1개)

Guillaume
Guillaume 2018년 10월 3일

0 개 추천

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).

카테고리

도움말 센터File Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품

릴리스

R2017b

질문:

2018년 10월 3일

편집:

2018년 10월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by