Syntax
[f,P]=getvarg(argin,paramstr,[npnp,P])
Input Parameter
argin : | | varargin |
paramstr : | | searchstring |
npnp : | | number of required arguments, default is 0 |
P : | | |
Property names
'' :
Output Parameter
f : | | false/true if the searchstring was found |
P : | | varargins following the searchstring
|
Examples
getvar(varargin,'verbose')>0
Copyright 2013-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, getvarg
, is designed to search through a list of input arguments (argin) for a specific string (paramstr) and return a flag (f) indicating whether the string was found, along with any subsequent arguments (P).
Input Parameters
- argin: A cell array of input arguments, typically passed as
varargin
in MATLAB functions.
- paramstr: The string to search for within
argin
.
- varargin: Optional parameters, where the first element can specify the number of required arguments following
paramstr
(npnp), and the second element can specify a default value for P.
Output Results
- f: An index (or 0) indicating the position of
paramstr
in argin
. If not found, f
is 0.
- P: The argument(s) following
paramstr
in argin
. If npnp
is specified, it returns that many arguments. If only one argument is found, it returns that argument directly.
Algorithm Steps
- Initialize
f
to 0 and P
to an empty cell array.
- Determine the number of required arguments (
np
) and default value for P
using getfuncparams
.
- If
argin
is not empty, iterate through each element:
- Check if the current element is a string and matches
paramstr
(case-insensitive).
- If a match is found, set
f
to the current index.
- If there is a subsequent element, assign it to
P
.
- Break the loop after finding the first match.
- If
np
is greater than 0 and there are enough elements, assign the next np
elements to P
.
- If
P
contains only one element, return it directly instead of as a cell array.
Algorithm explaination created using ChatGPT on 2025-08-19 07:47. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21