The Set and SetIndex Methods
You can use MATLAB® variables to set properties of a COMSOL Multiphysics model. Use the set or setIndex methods to pass the variable value from MATLAB to the COMSOL model.
The Set Methods
Use the set method to assign parameter and/or property values. All assignments return the parameter object, which means that assignment methods can be appended to each other.
The basic method for assignment is:
something.set(name, <value>)
The name argument is a string with the name of the parameter/property. The <value> argument can for example be a MATLAB integer or double array variable. <value> can also be a string, in this case the value or expression is defined within the model object.
When using a MATLAB variable, make sure that the value corresponds to the model unit system. COMSOL can also take care of the unit conversation automatically; in this case convert the MATLAB integer/double variable to a string variable and use the set method as:
something.set(property, [num2str(<value>)'[unit]'])
where is the unit you want to set the value property.
The SetIndex Methods
Use the setIndex method to assign values to specific indices (0-based) in an array or matrix property. All assignment methods return the parameter object, which means that assignment methods can be appended to each other:
something.setIndex(name, <value>, <index>)
The name argument is a string with the name of the property, <value> is the value to set the property, which can be a MATLAB variable value or a string, and <index> is the index in the property table.
When using a MATLAB variable make sure that the value corresponds to the model unit system. COMSOL can automatically take care of the unit conversation; in this case converting the MATLAB integer/double variable to a string variable and using the set method as:
something.setIndex(name, [num2str(<value>)'[unit]'], <index>)
where [unit] is the unit you want to set the value property.