Default Arguments in Matlab -
What is the default argument in MetLab? For example, here:
function wave (a, b, n, k, t, f, flag, fTrue = inline ( '0')) I should have an alternative argument for the true solution wave function. If this is possible, then can anyone show the proper way to do it? Currently, I'm trying to get what I posted above and I'm getting:
??? Error: File: Wave: M line: 1 column: 37 is not a valid target for expression assignment on the left of the equal sign. Thanks!
As far as I know, there is not a direct way to do it as if You have tried.
The general approach is to use passports and check against the number of ARGs. Something like this:
function F (arg1, arg2, arg3) if nargin & lt; 3 arg3 = 'some default' and end There are some myths that you can do with you, etc., and you may wish to see the matlab central for some packages that bundle them Do things like
[Update] Glad that helped.
You can have a look at varargin, nagark, etc. They are doing useful work for this kind of work. Varargs allow you to leave a variable number of final arguments, but this does not get you around the problem of default value for some / all.
Comments
Post a Comment