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 names = {}; 0044 kinds = {}; 0045 0046 %check input arguments 0047 if length(varargin)> 2 0048 error('Too many input arguments.'); 0049 end 0050 0051 if length(varargin)>= 1 0052 if ~ischar(varargin{1}) 0053 names = varargin{1}; 0054 else 0055 names = {varargin{1}}; 0056 end 0057 end 0058 0059 if length(varargin) == 2 0060 if ~ischar(varargin{2}) 0061 kinds = varargin{2}; 0062 else 0063 kinds = {varargin{2}}; 0064 end 0065 else 0066 kinds = []; 0067 end 0068 0069 0070 if length(kinds) == 0 0071 filterArray = []; 0072 end 0073 0074 for i=1:length(kinds) 0075 filterArray(i) = struct('key', 'kind', 'value', kinds(i)); 0076 end 0077 0078 % and make the actual call to 20-sim 0079 reply = xrlinvoke('xxsim.model.getVariables', struct('variables', {{ names, 'array' }}, 'filters', {{ filterArray, 'array' }} ) ); 0080 0081 retval = reply; 0082 0083 % matrices are returned as an array from xrlinvoke 0084 % change the array back to matrix of correct size 0085 0086 %disp("XXXXXXXXXX: size of reply is"), disp(size(reply)) 0087 %disp("XXXXXXXXXX: size of reply is"), disp(size(reply)(1)) 0088 0089 % loop through variables 0090 for i=1:size(reply)(1) 0091 % check if the variable is a matrix 0092 if ~isscalar(reply(i).size) 0093 retval(i).values = transpose(reshape(reply(i).values, reply(i).size(2),reply(i).size(1))); 0094 end 0095 end 0096 end 0097 %------------- END OF CODE --------------