matlabfunctioninput-parameters

How to choose pass value to one parameter to a MATLAB function with multiple inputs?


function [c,tc]=v_melcepst(s,fs,w,nc,p,n,inc,fl,fh)

This function has multiple input parameters, but I only want to specify the value for the nc parameter.

In Python, I can easily just do something like v_melcepst(nc=13), but I cannot find the equivalent for MATLAB.

Is this not possible in MATLAB? Do I have to pass default values?


Solution

  • This is indeed not possible in MATLAB. The arguments are sequential, identified by their location in the argument list.

    If you wrote the v_melcepst function yourself, you can rewrite it to accept "name/value pairs", the standard way in MATLAB to do named arguments. In this system, groups of two arguments together work as a single named argument. You would call the function as

     [c,tc] = v_melcepst('nc',nc);
    

    You can implement this using the old inputParser class (introduced in R2007a), or with the new function arguments block (new in R2019b).