Using External MATLAB® Functions
Another advantage of using LiveLink™ for MATLAB® is the ability to call a MATLAB® function directly from within the COMSOL Desktop®. You can use a function to define, within a COMSOL® model object, properties such as material definitions or physics settings. COMSOL Multiphysics automatically detects the external function and starts the MATLAB engine to evaluate it. The function output is then applied to the corresponding property.
To use this functionality, just start the COMSOL Desktop and MATLAB automatically starts in the background when needed.
Note: To run MATLAB functions with the model object, the preference Allow external MATLAB® functions needs to be set to either Yes or Ask. This preference can be found on the Security page of the Preferences window, available from the File (or Options) menu.
Note: On Linux® operating systems, specify the MATLAB root directory MLROOT and load the gcc library when you start the COMSOL Desktop: comsol -mlroot MLROOT -forcegcc. On some Linux systems you may need to replace the argument -forcegcc with -forcecomsolgcc.
The example in this section illustrates how to use external MATLAB functions in a COMSOL model. The model computes the temperature distribution in a material subjected to an external heat flux. Both the thermal conductivity of the material and the applied heat flux are defined by MATLAB functions.