-
Filter by Topic
Release
Popular Topics
- List all discussions
Tutorial: Working between COMSOL 4.1 and MATLAB 2010b
|
Thread index | Previous thread | Next thread | Start a new discussion |
March 8, 2011 10:01pm UTC
Tutorial: Working between COMSOL 4.1 and MATLAB 2010b
Ok, here is what I figured out in order to be able to take a COMSOL model, modify it in MATLAB and then reopen it in COMSOL for further work:
1. Launch COMSOL normally;
2. Launch MATLAB by using "COMSOL 4.1 with MATLAB";
In COMSOL:
- Saving your current COMSOL model into the COMSOL server:
a) File > Export Model to Server...
(Default settings: Server = localhost, Port = 2036)
Model = <filename> (Ex.: shell_diffusion)
(At that point, your COMSOL model is in the COMSOL server/buffer and is named "shell_diffusion")
In MATLAB:
- Loading your COMSOL model that you sent in the COMSOL server:
>> model = ModelUtil.model('shell_diffusion');
- Saving the file as a MATLAB .m-file:
>> model.save(<filename>, 'm'); (Ex.: model.save('shell_diffusion2', 'm'); )
(The file would be saved by default in the current working folder)
- In order to save the file in a specific folder:
>> model.save('C:\COMSOL_Models\shell_diffusion2', 'm');
(You now have created a MATLAB .m-file from a COMSOL file which you can edit and modify)
(I know, you could have just use the File > Save as Model M-File... option in COMSOL but I don't know how you could resend it to COMSOL that way)
- To save your modified model back into COMSOL:
>> model.save('C:\COMSOL_Models\shell_diffusion3'); (No specific file extension will save it as a .mph COMSOL file)
(You now have your COMSOL file back which you can reopen in COMSOL)
Reply | Reply with Quote | Send private message | Report Abuse
March 8, 2011 10:07pm UTC in response to Dominique
Re: Tutorial: Working between COMSOL 4.1 and MATLAB 2010b
Hi
Thanks for the tutorial, always useful, will check it out tomorrow
--
Good luck
Ivar
Reply | Reply with Quote | Send private message | Report Abuse
March 8, 2011 10:20pm UTC in response to Ivar Kjelberg
Re: Tutorial: Working between COMSOL 4.1 and MATLAB 2010b
I just forgot one thing:
- How to reload my modified M-file into the "model" in order to save it as a .mph...
Humm...inconvenient...
More to come later...
Reply | Reply with Quote | Send private message | Report Abuse
March 3, 2013 1:48am UTC in response to Ivar Kjelberg
Re: Tutorial: Working between COMSOL 4.1 and MATLAB 2010b
Hi Ivar,
I have a problem linking Comsol to Matlab.
I have Comsol 4.3a, Matlab R2011b, and the Comsol with Matlab program that came with Comsol.
I opened both programs. Then I created a model in Comsol. If I try to access the client server to transfer the model, it says:" Timeout on Connection attempt."
I then tried to save the model as .m file and then open it in the server prompt, it says: "unknown source." Even if I try to manually save the model as .mph file and then reopen in Matlab, it says:"unknown source."
I've done all the necessary link commands in the beginning and they were accepted.
Please advise.
Thanks,
Fred
Reply | Reply with Quote | Send private message | Report Abuse
March 3, 2013 8:33am UTC in response to Fred Tanyous
Re: Tutorial: Working between COMSOL 4.1 and MATLAB 2010b
Hi
Sorry but I'm no expert on Matlab to COMSOL liking. For me it works OK, but I had to reinstall COMSOL last time I updated Matlab. On the other hand there is a specal command in the COMSOl preferences to register matlab, I think, this should be done once, in case of problems.
Check the Knowledge Base (KB) there are a few entries, specifically for Matlab and COMSOL
--
Good luck
Ivar
Reply | Reply with Quote | Send private message | Report Abuse
Rules and guidelines

