Quantcast
Channel: Latest Discussions - COMSOL Forums
Viewing all articles
Browse latest Browse all 26527

Tutorial: Working between COMSOL 4.1 and MATLAB 2010b

$
0
0
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)

Viewing all articles
Browse latest Browse all 26527

Trending Articles