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.

Livelink MATLAB problem

Please login with a confirmed email address before reporting spam

Dear Sir/Madam,
I have previously tried earlier version of COMSOL, Now I am using COMSOL 4.1 and MATLAB 2010b on windows 7 machine. I follow the instruction inside the Livelink manual. However, I cannot use COMSOL functionality in MATLAB yet. As an example for [transport_and_adsorption.mph] , here is what I do:
1-connect to the COMSOL Multiphysics 4.1 server,
2-add the MLI folder to MATLAB path,
3- Export the MPH file "Export Model to Server";
4- Save Model as M-File
5- Type these in MATLAB:
mphstart
model = mphload('transport_and_adsorption')
transport_and_adsorption

Matlab shows:
Type: Root
Tag: Model
Identifier: root

I have attached the structure forms in MATLAB at this stage. I expect that keywords like femtime, works here, however it does not. Also when I call the same function (transport_and_adsorption) it only gives the above output..no calculation!
Would you please advice on these two inquires?
1-What I do to link MATALAB and COMSOL is correct or not? If not, what else shall I do?
2- How can I command COMSOL generated m-file or comsol mph file from MATLAB for a certain computational purpose?

I look forward to hearing from you.
Best regards
Mona



3 Replies Last Post 29 juil. 2014, 05:34 UTC−4
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 10 mai 2011, 08:21 UTC−4
Hi Mona

When you start you should choose the icon "COMSOL 4.1. with MATLAB" after this step you are ready to execute commands that will use Comsol.

E.g. in order to load your model and solve, you'll do:

model = mphload('transport_and_adsorption')
model.sol('sol1').run

The LiveLink for MATLAB is based on the Java API for COMSOL. The first line calling mphload is a convenience function that merely calls this function in the API:
ModelUtil.load('Model', 'filename')
but is also has some code that e.g. looks for model files in the model library that the ModelUtil.load model doesn't handle. There are many convenience functions (e.g. mphgeom, mphinterp, mphplot) that all have Matlab help. Jjust write help mphplot to see the help text or look into the LiveLink for MATLAB user's guide.

The second line is a call using java directly:
model.sol('sol1').run
in this case the solver is started in the Comsol server and Matlab will wait for the solver to finish.

In order to learn about the java calls you can do two different things:
1) Read the documentation. There is a user's guide for the LiveLink for MATLAB and a COMSOL Multiphysics API Guide that you need to study

2) Create a model using the Comsol Desktop and save an m-file in order to learn the syntax from studying the m-file.


Lars Gregersen
Comsol Denmark
Hi Mona When you start you should choose the icon "COMSOL 4.1. with MATLAB" after this step you are ready to execute commands that will use Comsol. E.g. in order to load your model and solve, you'll do: model = mphload('transport_and_adsorption') model.sol('sol1').run The LiveLink for MATLAB is based on the Java API for COMSOL. The first line calling mphload is a convenience function that merely calls this function in the API: ModelUtil.load('Model', 'filename') but is also has some code that e.g. looks for model files in the model library that the ModelUtil.load model doesn't handle. There are many convenience functions (e.g. mphgeom, mphinterp, mphplot) that all have Matlab help. Jjust write help mphplot to see the help text or look into the LiveLink for MATLAB user's guide. The second line is a call using java directly: model.sol('sol1').run in this case the solver is started in the Comsol server and Matlab will wait for the solver to finish. In order to learn about the java calls you can do two different things: 1) Read the documentation. There is a user's guide for the LiveLink for MATLAB and a COMSOL Multiphysics API Guide that you need to study 2) Create a model using the Comsol Desktop and save an m-file in order to learn the syntax from studying the m-file. Lars Gregersen Comsol Denmark

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 18 mai 2011, 00:08 UTC−4
Dear Lars,

Thank you so much for your useful information. I tried one of the example that exists in MATLAB guide and it seems that these two software are linked together but I am still confuse because in previous version I have the icon of COMSOL with MATLAB, but in COMSOL 4.1 I could not find this icon anywhere. I don know why?
Best regards
Mona
Dear Lars, Thank you so much for your useful information. I tried one of the example that exists in MATLAB guide and it seems that these two software are linked together but I am still confuse because in previous version I have the icon of COMSOL with MATLAB, but in COMSOL 4.1 I could not find this icon anywhere. I don know why? Best regards Mona

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 29 juil. 2014, 05:34 UTC−4
this link may be helpful to you, check it
www.comsol.co.in/community/forums/general/thread/989/
this link may be helpful to you, check it http://www.comsol.co.in/community/forums/general/thread/989/

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.