mardi 14 février 2017

Parse mutually exclusive input arguments with MATLAB's input parser

Vote count: 0

I have a function that has at least two required input arguments. Depending on the value of the second argument, there might be a third required input argument. I am wondering what is the best way to code a robust function that incorporates these requirements using MATLAB's input parser?

The function may look like this:

function vout = test(ReqInpArg1, ReqInpArg2, varargin)

ReqInpArg2 may hold the following string content:

  • 'cash'
  • 'absHurdleRate'
  • 'none'

If the user chooses cash, than another input argument numCashTicker needs to be defined as part of varargin, e.g. 'numCashTicker', 4. If absHurdleRatehas been choosen, a different input parameter has to be defined, e.g. 'hurdleRate', 0.2. If, on the other hand, none has been chosen, none of these input parameter must be defined. As a matter of fact, numCashTicker and hurdleRate are mutually exclusive, i.e. they must not be defined at the same time. In addition, if the user didn't chose none, he must define one of the other varargin input arguments.

What is best practice / the best strategy in order to implement these requirements?

asked 14 secs ago

Let's block ads! (Why?)



Parse mutually exclusive input arguments with MATLAB's input parser

Aucun commentaire:

Enregistrer un commentaire