Using a MATLAB® Function to Define Model Properties
Use MATLAB® Function to define the model property. The function can either be declared within the model object or called at the MATLAB prompt.
Calling MATLAB Functions within the COMSOL Model object
LiveLink™ for MATLAB® enables you to declare a MATLAB M-function directly from within the COMSOL Multiphysics model object. This is typically the case if you want to call a MATLAB M-function from the COMSOL Desktop. The function being declared within the model object accepts any parameter, variable, or expression arguments defined in the COMSOL model object. However, to use a variable defined at the MATLAB prompt, the variable has to be transferred first in the COMSOL model as a parameter, for example (see how to set a MATLAB variable in the COMSOL model in The Set and SetIndex Methods).
The function is evaluated any time the model needs to be updated. The model object cannot be called as an input argument of the M-function.
Calling MATLAB Functions at the MATLAB Prompt
Use a MATLAB function to define a model property with the set method:
feature.set(property, myfun(<arg>))
where myfun() is an M-function defined in MATLAB.
The function is called only when the command is executed at the MATLAB prompt. The argument of the function <arg> called can be MATLAB variables. To include an expression value from the model object, first extract it at the MATLAB prompt, as described in Extracting Results.
The function myfun() accepts the model object model as an input argument as any MATLAB variable.