MATLAB: How to create function with name-value pair arguments functionMATLABname-value pair arguments Hello. I want to create the function like function [x1, x2] = fun('name',varargin,'name',[..],'name',[..]) How i can do it? Best Answer https://www.mathworks.com/help/matlab/ref/inputparser.html Note: in R2019b and later, see the new arguments keywordhttps://www.mathworks.com/help/matlab/matlab_prog/function-argument-validation-1.html Related SolutionsMATLAB: What does the varargin function do and what does varargin{:} mean "What does the varargin function do..."varargin is not a function, it is a cell array which contains any number of optional input arguments:https://www.mathworks.com/help/matlab/ref/varargin.html"... and what does varargin{:} mean?"That syntax creates a comma-separated list from the cell array varargin:https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.htmlhttps://www.mathworks.com/matlabcentral/answers/320713-how-to-operate-on-comma-separated-listshttps://www.mathworks.com/company/newsletters/articles/matlab-tips-and-tricks-exploiting-the-comma-separated-list-vectorizing-cell-array-and-structure-references.htmlSo your example is equivalent to this:[varargin{1},varargin{2},...,varargin{end}] = convertStringsToChars(varargin{1},varargin{2},...,varargin{end}); MATLAB: Name-value pairs You can use reshapefunction C = name_value_pairs(varargin) if nargin == 0 || rem(numel(varargin),2) ~= 0 C = {}; return; end C = reshape(varargin, 2, []).'; if ~all(cellfun(@ischar, C)) C = {} endend Related QuestionName-Value Pairs errorInterpreting varargin name-value pairs.Not enough input argumentsInput parsing of name-value Pairs
Best Answer