


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

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 %check input arguments 0028 if ~ischar(names) 0029 use_names = names; 0030 else 0031 use_names = {names}; 0032 end 0033 0034 if iscell(values) 0035 use_values = values; 0036 else 0037 use_values = {values}; 0038 end 0039 0040 % test if the given arguments have the same length 0041 if length(use_names) ~= length(use_values) 0042 error('array size mismatch in given names and values'); 0043 end 0044 0045 % create a an array of struct with name and values 0046 for i=1:length(use_names) 0047 0048 valueSize = size(use_values{i}); 0049 0050 % create the size array 0051 if valueSize(2) == 1 0052 mysize = int32(valueSize(1)); 0053 else 0054 if ischar(use_values{i}) 0055 mysize = int32(1); 0056 else 0057 mysize = [int32(valueSize(1) ), int32(valueSize(2))]; 0058 end 0059 end 0060 0061 %For matlab compatibility create the first element without index. 0062 if i == 1 0063 variables = struct('name', use_names{i}, 'size', {{mysize, 'array'}}, 'value', {{use_values{i}, 'array'}}); 0064 else 0065 variables(i)= struct('name', use_names{i}, 'size', {{mysize, 'array'}}, 'value', {{use_values{i}, 'array'}}); 0066 end 0067 0068 end 0069 0070 % and make the actual call to 20-sim 0071 reply = xrlinvoke('xxsim.model.setVariables', {variables, 'array'} ); 0072 0073 retval = reply; 0074 end 0075 %------------- END OF CODE --------------