Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

How can I use matlab console and comsol desktop at the same time?

Please login with a confirmed email address before reporting spam

When I run `comsol server matlab`, there is only a matlab console popped out. If I want to see what my matlab scripts done, I have to use mphplot to plot them. It takes time to write the mphplot script, so it is not very convenient for script debugging.

Therefore, I want to know if there is anyway to view the model change or calculation results in a comsol desktop window as soon as the matlab scripts run?

Thanks

1 Reply Last Post Jan 23, 2015, 12:49 a.m. EST

Please login with a confirmed email address before reporting spam

Posted: 10 years ago Jan 23, 2015, 12:49 a.m. EST
I figure it out myself.

use command line:
foo@bar$ comsol server matlab
to run a server and run a matlab client at the same time.

use command line:
foo@bar$ comsol client
to run a comsol desktop client.

connect the comsol desktop client to the server we just created.

create model from matlab client, using scripts you want to test. For example:

===test.m===
function out = test()
import com.comsol.model.*
import com.comsol.model.util.*
model = ModelUtil.create('Model');
model.modelPath('/tmp');
model.modelNode.create('comp1');
model.geom.create('geom1', 3);
model.mesh.create('mesh1', 'geom1');
model.geom('geom1').create('blk1', 'Block');
model.geom('geom1').runAll();
out = model;
===test.m===

run this script in matlab console:
>>> m=test();
to obtain the model in the variable 'm'.

The test.m above created a box, we may want to view it in the comsol desktop window.

Turn to the comsol desktop, in 'File' menu, in submenu 'Client Server', click 'Import Model from Server'.

After importing model, we shall see the box in the comsol desktop then. Try this script in matlab:

>>> m.geom('geom1').delete('blk1');

then the block in the comsol desktop should disappear ~ That shows the matlab operation effect in comsol desktop.
I figure it out myself. use command line: foo@bar$ comsol server matlab to run a server and run a matlab client at the same time. use command line: foo@bar$ comsol client to run a comsol desktop client. connect the comsol desktop client to the server we just created. create model from matlab client, using scripts you want to test. For example: ===test.m=== function out = test() import com.comsol.model.* import com.comsol.model.util.* model = ModelUtil.create('Model'); model.modelPath('/tmp'); model.modelNode.create('comp1'); model.geom.create('geom1', 3); model.mesh.create('mesh1', 'geom1'); model.geom('geom1').create('blk1', 'Block'); model.geom('geom1').runAll(); out = model; ===test.m=== run this script in matlab console: >>> m=test(); to obtain the model in the variable 'm'. The test.m above created a box, we may want to view it in the comsol desktop window. Turn to the comsol desktop, in 'File' menu, in submenu 'Client Server', click 'Import Model from Server'. After importing model, we shall see the box in the comsol desktop then. Try this script in matlab: >>> m.geom('geom1').delete('blk1'); then the block in the comsol desktop should disappear ~ That shows the matlab operation effect in comsol desktop.

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.