Discussion Forum

Import Matlab m-file back to COMSOL

Topics: MATLAB, 4.2a

Thread index  |  Previous thread  |  Next thread  |  Start a new discussion

RSS FeedRSS feed   |   Email notificationsTurn on email notifications   |   7 Replies   Last post: January 25, 2012 6:51pm UTC
Wan Kuang

Wan Kuang

August 4, 2009 4:00pm UTC

Import Matlab m-file back to COMSOL

Hi,

I have a Matlab m-file that was generated by COMSOL previously. I made some changes since. Now I wonder if it is possible to import it back to COMSOL again. Thanks.

Wan

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

John Chitalia

John Chitalia

August 4, 2009 7:10pm UTC in response to Wan Kuang

Re: Import Matlab m-file back to COMSOL

Are you running the software with the COMSOL Multiphysics with MATLAB shortcut? You should see File > Import > FEM Structure.

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Wan Kuang

Wan Kuang

August 5, 2009 12:56pm UTC in response to John Chitalia

Re: Import Matlab m-file back to COMSOL

It doesn't seem to import boundary conditions. Any ways to import those as well.

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Pasquale Franciosa

Pasquale Franciosa

August 5, 2009 7:15pm UTC in response to Wan Kuang

Re: Import Matlab m-file back to COMSOL

Hi,
if you have matlab connection to comsol, you can save the m file from comsol, modify the file in matlab and then re-load the so-modified file in comsol (file>open>.mfile). Anyway, you can also export the fem structure (file>export>fem) and view the variable within the matlab workspace. If you know the fem structure with its fields you can modify it and then re-load in comsol (file>import>fem) where you can run the solution.
On the other hand, if you save the m.file you can run the model directly from matlab (without using comsol again).

If you do not delete or modify the field fem{1}.appl.bnd, boundary conditions are correctly imported . You can verify it...

Good luck

Pasquale

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Dominique

Dominique

March 9, 2011 2:17pm UTC in response to John Chitalia

Re: Import Matlab m-file back to COMSOL


Are you running the software with the COMSOL Multiphysics with MATLAB shortcut? You should see File > Import > FEM Structure.


This is not valid anymore in COMSOL 4.1

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Mazyar Amin

Mazyar Amin

April 21, 2011 2:13pm UTC in response to Pasquale Franciosa

Re: Import Matlab m-file back to COMSOL


Hi,
if you have matlab connection to comsol, you can save the m file from comsol, modify the file in matlab and then re-load the so-modified file in comsol (file>open>.mfile). Anyway, you can also export the fem structure (file>export>fem) and view the variable within the matlab workspace. If you know the fem structure with its fields you can modify it and then re-load in comsol (file>import>fem) where you can run the solution.
On the other hand, if you save the m.file you can run the model directly from matlab (without using comsol again).

If you do not delete or modify the field fem{1}.appl.bnd, boundary conditions are correctly imported . You can verify it...

Good luck

Pasquale


Hi,

I am using V3.5a. After exporting an m file from COMSOL to Matlab, I can see the changes that I make in COMSOL's GUI are implemented in MATLAB's script. But I cannot do the other way around, i.e. after I make a modification in the geometry in MATLAB script, I save the m file and open it in COMSOL, and I get this error:

Error: 9040
Fatal Error.
Type: NullPointerException

Any idea why this happens?

Thanks,
Manuel

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Nikita Jayswal

Nikita Jayswal

January 25, 2012 11:11am UTC in response to Mazyar Amin

Re: Import Matlab m-file back to COMSOL



Hi,
if you have matlab connection to comsol, you can save the m file from comsol, modify the file in matlab and then re-load the so-modified file in comsol (file>open>.mfile). Anyway, you can also export the fem structure (file>export>fem) and view the variable within the matlab workspace. If you know the fem structure with its fields you can modify it and then re-load in comsol (file>import>fem) where you can run the solution.
On the other hand, if you save the m.file you can run the model directly from matlab (without using comsol again).

If you do not delete or modify the field fem{1}.appl.bnd, boundary conditions are correctly imported . You can verify it...

Good luck

Pasquale


Hi,

I am using V3.5a. After exporting an m file from COMSOL to Matlab, I can see the changes that I make in COMSOL's GUI are implemented in MATLAB's script. But I cannot do the other way around, i.e. after I make a modification in the geometry in MATLAB script, I save the m file and open it in COMSOL, and I get this error:

Error: 9040
Fatal Error.
Type: NullPointerException

Any idea why this happens?

Thanks,
Manuel


Hi

I am facing the same problem.. I am using Comsol 4.2a and matlab 2008a and when i save the changes in the Matlab m-file for the comsol model, it does not recognize the changed parameters. Also, does anyone know how i can use matlab variables in a Matlab-Simulink-Comsol interface problem where i declare a comsol variable = a time dependent matlab variable through the simulink sfunction. so basically i cannot use the matlab functions through livelink and i need to use the matlab variables.

any sort of help would be appreciated. thanks a lot!

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Francois Gregoire

Francois Gregoire

January 25, 2012 6:51pm UTC in response to Nikita Jayswal

Re: Import Matlab m-file back to COMSOL

Nikita,

Have you tried the command 'mphsave'? It converts a .m to .mph, see the Livelink for Matlab User's Guide or type 'help mphsave' in Matlab. It works just fine here with comsol 4.2a and Matlab R2011a.

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse


Rules and guidelines