Extendable, but bacward compatible M code.

1 次查看(过去 30 天)
What is the best way of creating M code that can easily be extended, but will remain backward compatible? When creating code, it is beneficial to try to predict future use along with the present use, e.g., which parameters could potentially be of interest to the user.?
It is not possible to predict all parameters that potentially will be changed by future users. How can my M code deal with this problem and still be simple and easy to read?
One solution is to include a struct as parameter to the function. This struct can be extended by new fields, if required.

采纳的回答

Martijn
Martijn 2011-2-25
Working with structures is indeed an option. Other options include working with VARARGIN and VARARGOUT:
Or you could consider working with the inputParser which allows easy implementation of 'parameter', value pairs:
(You could easily add new optional fields later on)

更多回答(1 个)

Jesper
Jesper 2011-2-28
Thanks for your answer. It led me to the following page:
http://blogs.mathworks.com/loren/2009/05/05/nice-way-to-set-function-defaults/
There seems to many ways to achieve backward compatible code. However, no "standard" Matlab way to do it.

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by