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.

Import Matlab m-file back to COMSOL

Please login with a confirmed email address before reporting spam

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

8 Replies Last Post Jul 21, 2016, 4:31 p.m. EDT

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Aug 4, 2009, 3:10 p.m. EDT
Are you running the software with the COMSOL Multiphysics with MATLAB shortcut? You should see File > Import > FEM Structure.
Are you running the software with the COMSOL Multiphysics with MATLAB shortcut? You should see File > Import > FEM Structure.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Aug 5, 2009, 8:56 a.m. EDT
It doesn't seem to import boundary conditions. Any ways to import those as well.
It doesn't seem to import boundary conditions. Any ways to import those as well.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Aug 5, 2009, 3:15 p.m. EDT
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, 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

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 9, 2011, 9:17 a.m. EST

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
[QUOTE] Are you running the software with the COMSOL Multiphysics with MATLAB shortcut? You should see File > Import > FEM Structure. [/QUOTE] This is not valid anymore in COMSOL 4.1

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 21, 2011, 10:13 a.m. EDT

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
[QUOTE] 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 [/QUOTE] 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

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 25, 2012, 6:11 a.m. EST


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!
[QUOTE] [QUOTE] 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 [/QUOTE] 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 [/QUOTE] 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!

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 25, 2012, 1:51 p.m. EST
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.
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.

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Jul 21, 2016, 4:31 p.m. EDT
How to import comsol model into simulink (Matlab)?
How to import comsol model into simulink (Matlab)?

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.