S = getvar(STR), where the string STR is in the form 'p1=v1_p2=v2_...',
returns a structure S containing the variables built from STR, with
S.p1=v1, S.p2=v2, etc. If the substrings separated by '_' do
not contain any '=', the first block of alphanumeric characters stands
for the variable name, and the remaining of the substring is the value
for that variable. If the substrings consist only of alphanumerics or
digits, then a generic variable name in the form 'varxx' is generated.
This function is useful to read the parameters stored into filenames.
Example
getvar('050211_180_dt18.5_h0=80_mode=drop')
var1: 50211
var2: 180
dt: 18.5000
h0: 80
mode: 'drop'
If STR is a cell array of string, getvar loops over each element and
returns a cell array of structures.
VAR = getvar(STR, VARNAME) returns the value of the variable VARNAME.
VAR = getvar(STR, N) returns the Nth variable.
Example
getvar('a12_b3_c5...','b')
3
The variables are converted to numeric whenever a numeric conversion
is possible. To keep all variables as strings, specify 'strings' as the
3rd parameter: getvar(STR, VARNAME, 'strings'). (use VARNAME=[] if you
do not specify any VARNAME).
Examples
getvar('050211_180_dt18.5_h0=80_mode=drop','dt')
18.5000
getvar('050211_180_dt18.5_h0=80_mode=drop','dt','strings')
'18.5'
See Also
getattribute, getfilenum.
Published output in the Help browser
showdemo getvar