


xxsimGetVariables - get specified variables.
Syntax:
retval = xxsimGetVariables('variable_name')
retval = xxsimGetVariables({'variable1_name', 'variable2_name'})
retval = xxsimGetVariables({'submodel_names'},{'variable_kinds'})
Inputs:
variable_name = name of a variable with hierarchy e.g 'PID.Kp'.
submodel_names = (optional) name(s) or submodel(s) in which the variables are found.
Note: if no name is specified ({}) all variables are retrieved.
variable_kinds = (optional) kind of the variable requested
e.g 'parameter','variable','state','rate', 'initialValue',
'dependentRate','algebraic','algebraicin','algebraicout',
'constraint','constraintin','constraintout'.
Note: if kind is NOT specified all kinds are retrieved.
Outputs:
retval = returns a structure array with the requested variables.
Examples:
retval = xxsimGetVariables({'PID','Amplifier'}, {'parameter','state'})
- retval now contains the list of parameters and state variables
found in the submodels PID and Amplifier.
- the output is returned in a structure array form.
e.g
retval.name : returns the name(s) of retrieved variable(s).
retval.size : returns the size of the variable(s).
retval.values : returns the value(s).
retval.properties : returns the properties of the variable(s).
See also: xxsimSetParameters, xxsimSetVariables, xxsimGetParameters
Author: Controllab Products B.V.
email: info@controllab.nl
Website: http://www.controllab.nl
September 2013

0001 function retval = xxsimGetVariables(varargin) 0002 % xxsimGetVariables - get specified variables. 0003 % 0004 % Syntax: 0005 % retval = xxsimGetVariables('variable_name') 0006 % retval = xxsimGetVariables({'variable1_name', 'variable2_name'}) 0007 % retval = xxsimGetVariables({'submodel_names'},{'variable_kinds'}) 0008 % 0009 % Inputs: 0010 % variable_name = name of a variable with hierarchy e.g 'PID.Kp'. 0011 % submodel_names = (optional) name(s) or submodel(s) in which the variables are found. 0012 % Note: if no name is specified ({}) all variables are retrieved. 0013 % variable_kinds = (optional) kind of the variable requested 0014 % e.g 'parameter','variable','state','rate', 'initialValue', 0015 % 'dependentRate','algebraic','algebraicin','algebraicout', 0016 % 'constraint','constraintin','constraintout'. 0017 % Note: if kind is NOT specified all kinds are retrieved. 0018 % 0019 % Outputs: 0020 % retval = returns a structure array with the requested variables. 0021 % 0022 % Examples: 0023 % retval = xxsimGetVariables({'PID','Amplifier'}, {'parameter','state'}) 0024 % 0025 % - retval now contains the list of parameters and state variables 0026 % found in the submodels PID and Amplifier. 0027 % - the output is returned in a structure array form. 0028 % e.g 0029 % retval.name : returns the name(s) of retrieved variable(s). 0030 % retval.size : returns the size of the variable(s). 0031 % retval.values : returns the value(s). 0032 % retval.properties : returns the properties of the variable(s). 0033 % 0034 % See also: xxsimSetParameters, xxsimSetVariables, xxsimGetParameters 0035 % 0036 % Author: Controllab Products B.V. 0037 % email: info@controllab.nl 0038 % Website: http://www.controllab.nl 0039 % September 2013 0040 0041 %------------- BEGIN CODE -------------- 0042 0043 %check input arguments 0044 if length(varargin)> 2 0045 error('Too many input arguments.'); 0046 end 0047 0048 if length(varargin)>= 1 0049 if ~ischar(varargin{1}) 0050 names = varargin{1}; 0051 else 0052 names = {varargin{1}}; 0053 end 0054 else 0055 names = {}; 0056 end 0057 0058 if length(varargin) == 2 0059 if ~ischar(varargin{2}) 0060 kinds = varargin{2}; 0061 else 0062 kinds = {varargin{2}}; 0063 end 0064 else 0065 kinds = []; 0066 end 0067 0068 0069 if isempty(kinds) 0070 filterArray = []; 0071 end 0072 0073 for i=1:length(kinds) 0074 filterArray(i) = struct('key', 'kind', 'value', kinds(i)); 0075 end 0076 0077 % and make the actual call to 20-sim 0078 reply = xrlinvoke('xxsim.model.getVariables', struct('variables', {{ names, 'array' }}, 'filters', {{ filterArray, 'array' }} ) ); 0079 0080 retval = reply; 0081 0082 % matrices are returned as an array from xrlinvoke 0083 % change the array back to matrix of correct size 0084 0085 % loop through variables 0086 size_reply = size(reply); 0087 for i=1:size_reply(1) 0088 % check if the variable is a matrix 0089 if ~isscalar(reply(i).size) 0090 retval(i).values = transpose(reshape(reply(i).values, reply(i).size(2),reply(i).size(1))); 0091 end 0092 end 0093 end 0094 %------------- END OF CODE --------------