Connecting a COMSOL Server and MATLAB® Manually
Manually connecting MATLAB® to a COMSOL server can be useful if you want to start a MATLAB standalone and then connect to a COMSOL server, or if you need to connect MATLAB and a COMSOL server running on different computers. LiveLink™ for MATLAB® provides the function mphstart to operate the client/server connection. This section contains the instruction to follow to connect MATLAB to either a COMSOL Multiphysics Server or the COMSOL Server™.
Connecting MATLAB to a COMSOL Multiphysics Server
Starting a COMSOL Multiphysics Server
On Windows, click COMSOL Multiphysics Server in the COMSOL Launchers folder underneath your COMSOL Multiphysics folder on the Windows Start menu.
On Mac OS X or Linux enter comsol mphserver at a terminal window.
Connecting MATLAB to the COMSOL Multiphysics Server
1
2
mphstart
If the COMSOL Multiphysics Server started listening to a different port than the default one (which is 2036) use the mphstart function as in the command below:
mphstart(<portnumber>)
where <portnumber> is an integer corresponding to the port used by the COMSOL server.
Connecting MATLAB and a server on Different Computers
To connect MATLAB and a COMSOL server that are running on different computers, specify the IP address of the computer where the COMSOL server is running in the function mphstart:
mphstart(<ipaddress>, <portnumber>)
<ipaddress> can also be defined with the COMSOL server domain name.
The command above assume that the same user login information are set on the server and client machine. In case the login information are not accessible from the client machine, specify manually the user name and password to the COMSOL server with the command:
mphstart(<ipaddress>, <portnumber>, <username>, <password>)
If the COMSOL Multiphysics installation folder cannot be found automatically, you can specify its location manually as in the command below:
mphstart(<ipaddress>, <portnumber>, <comsolpath>)
where <comsolpath> is the path of the COMSOL installation folder.
You can also specify all the information to connect a COMSOL server within the same command, use the following command:
mphstart(<ipaddress>, <portnumber>, <comsolpath>, ...
   <username>, <password>)
Memory Settings
To be able to manipulate the model object and extract data at the MATLAB prompt, you may need to modify the Java® heap size in MATLAB. See Improving Performance for Large Models.
Importing the COMSOL Class
Once MATLAB and the COMSOL server are manually connected, import the COMSOL class by entering the following command at the MATLAB prompt:
import com.comsol.model.util.*
Disconnecting MATLAB and the COMSOL server
To disconnect MATLAB and the COMSOL server, run this command at the MATLAB prompt:
ModelUtil.disconnect;