xxsimSetVariables

PURPOSE ^

xxsimSetVariables - sets specified variables.

SYNOPSIS ^

function retval = xxsimSetVariables(names, values)

DESCRIPTION ^

 xxsimSetVariables - sets specified variables. 

 Syntax: 
   retval = xxsimSetVariables(names, values)

 Inputs:
   names  = names of the variables to be set.
   values = the new values of the variables.
 
 Outputs: 
   retval = returns true if the variable is set properly.

 Examples:
   xxsimSetVariables({'Controller_Continuous.kp', 'Controller_Discrete.kp'},{3,4});

      - sets 'Controller_Continuous.kp' and 'Controller_Discrete.kp' to 3 and 4 respectively.

 See also: xxsimSetParameters, xxsimGetVariables, xxsimGetParameters

 Author: Controllab Products B.V.
 email: info@controllab.nl
 Website: http://www.controllab.nl
 September 2013

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function retval = xxsimSetVariables(names, values)
0002 % xxsimSetVariables - sets specified variables.
0003 %
0004 % Syntax:
0005 %   retval = xxsimSetVariables(names, values)
0006 %
0007 % Inputs:
0008 %   names  = names of the variables to be set.
0009 %   values = the new values of the variables.
0010 %
0011 % Outputs:
0012 %   retval = returns true if the variable is set properly.
0013 %
0014 % Examples:
0015 %   xxsimSetVariables({'Controller_Continuous.kp', 'Controller_Discrete.kp'},{3,4});
0016 %
0017 %      - sets 'Controller_Continuous.kp' and 'Controller_Discrete.kp' to 3 and 4 respectively.
0018 %
0019 % See also: xxsimSetParameters, xxsimGetVariables, xxsimGetParameters
0020 %
0021 % Author: Controllab Products B.V.
0022 % email: info@controllab.nl
0023 % Website: http://www.controllab.nl
0024 % September 2013
0025 
0026 %------------- BEGIN CODE --------------
0027     use_names = {};
0028     use_values = {};
0029 
0030     %check input arguments
0031     if ~ischar(names)
0032         use_names = names;
0033     else
0034         use_names = {names};
0035     end
0036 
0037     if iscell(values)
0038         use_values = values;
0039     else
0040         use_values = {values};
0041     end
0042 
0043     % test if the given arguments have the same length
0044     if length(use_names) ~= length(use_values)
0045         error('array size mismatch in given names and values');
0046     end
0047     
0048     % create a an array of struct with name and values
0049     for i=1:length(use_names)
0050         
0051         valueSize = size(use_values{i});
0052         
0053         % create the size array
0054         if valueSize(2) == 1
0055             mysize = int32(valueSize(1));
0056         else
0057             if ischar(use_values{i})
0058                 mysize = int32(1);
0059             else
0060                 mysize = [int32(valueSize(1) ), int32(valueSize(2))];
0061             end
0062         end
0063 
0064         %For matlab compatibility create the first element without index.
0065         if i == 1
0066             variables = struct('name', use_names{i}, 'size', {{mysize, 'array'}}, 'value', {{use_values{i}, 'array'}});
0067         else
0068             variables(i)= struct('name', use_names{i}, 'size', {{mysize, 'array'}}, 'value', {{use_values{i}, 'array'}});    
0069         end
0070             
0071     end
0072       
0073     % and make the actual call to 20-sim
0074     reply = xrlinvoke('xxsim.model.setVariables', {variables, 'array'} );
0075     
0076     retval = reply;
0077 end
0078 %------------- END OF CODE --------------

Generated on Sun 10-Dec-2017 19:24:51