Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

converting COMSOL code to the MATLAB ???

Hello,

I'm working with COMSOL to simulate a chemical experience, but it takes too much time to display the results.
So i want to find a link between comsol and matlab if i can convert the code of comsol to matlab that will be faster than using comsol alone !!!
So am asking if i can do this and how ????


watting your answer
thank you very much :)

5 Replies Last Post Jun 1, 2012, 10:20 AM EDT
Mohammad Goharkhah
Posted: 5 years ago Apr 26, 2012, 9:31 AM EDT
Hi
you can simply save your comsol model as a MATLAB m.file

In the comsol file menu/ save As model mfile
Hi you can simply save your comsol model as a MATLAB m.file In the comsol file menu/ save As model mfile

Posted: 5 years ago Apr 26, 2012, 9:50 AM EDT
hi Mohammad ,

thank so much for your attention . i juste did what you say but when I execute the code in matlab, it doesn't work against in comsol it works very good !!
You can find out how I can solve this problem ?
thank's again
hi Mohammad , thank so much for your attention . i juste did what you say but when I execute the code in matlab, it doesn't work against in comsol it works very good !! You can find out how I can solve this problem ? thank's again

Mohammad Goharkhah
Posted: 5 years ago Apr 26, 2012, 10:00 AM EDT
Hi
Before executing the code in MATLAB, you should "run comsol with matlab"
go to the start menu/All programs/ comsol/ run comsol with matlab
then, you can run the mfile
Hi Before executing the code in MATLAB, you should "run comsol with matlab" go to the start menu/All programs/ comsol/ run comsol with matlab then, you can run the mfile

Francois Gregoire
Posted: 5 years ago Apr 27, 2012, 3:09 PM EDT
here are the steps:

Step in Comsol:
- save model as .m

Start 'Comsol with Matlab'

Steps in Matlab:
- open the .m
- put first and last lines of the code in comments:
% function out = model
...code...
% out = model;
- at the end of the code, insert lines to extract results, here is an example for heat transfer, see the docs for mpheval:
T = mpheval(model,'T') % temperature
kx = mpheval(model,'ht.kxx') % thermal conductivity in x
- Run your .m (F5) and see the extracted data in the matlab workspace
- The postprocessing world is yours!


here are the steps: Step in Comsol: - save model as .m Start 'Comsol with Matlab' Steps in Matlab: - open the .m - put first and last lines of the code in comments: % function out = model ...code... % out = model; - at the end of the code, insert lines to extract results, here is an example for heat transfer, see the docs for mpheval: T = mpheval(model,'T') % temperature kx = mpheval(model,'ht.kxx') % thermal conductivity in x - Run your .m (F5) and see the extracted data in the matlab workspace - The postprocessing world is yours!

Posted: 5 years ago Jun 1, 2012, 10:20 AM EDT
Thanks.Good Hints.
Thanks.Good Hints.

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.