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.
Exporting Comsol data to Matlab?
Posted 18.11.2009, 07:00 GMT-5 Interfacing, LiveLink for MATLAB, Parameters, Variables, & Functions, Results & Visualization, Structural Mechanics Version 4.2, Version 5.2 14 Replies
Please login with a confirmed email address before reporting spam
I want to postprocess Comsol data in Matlab. Since Ascii files blow up in size and I get "out of memory error", I'm looking for some other way. I've no experience with Comsol-Matlab interface and it seems to me that this interface is not working in my system.
Could someone please tell me, how to export Postprocessing data in some Matlab-compatible format (not Ascii)?
I've converted a Comsol model (after executing) into an m-file and wanted to run it in Matlab (running separately from Comsol) but Matlab is probably not able to read the flbinaryfile (*.mphm). Any suggestion, what could be wrong here?
Thanks.
Daniel
Please login with a confirmed email address before reporting spam
You need to get your link between COMSOL and Matlab up running, either you missed a step during the installation of COMSOL or some of the files added to matlab are not set up correctly. Have a look at the installation documentation of COMSOL (I beleive ther are other comments in the forum and on the support KB pages).
Once you have the link running, you can (in V3.5a) just do a File "connect" to matlab from the COSOL GUI and export the "fem" structure to Matlab by a CNTRL-F.
then you need to understand the "fem" structure (see mlinterface.pdf in the COMSOL doc) to extract the data in binay mode and you can continue your processing at will.
Good luck
Ivar
Please login with a confirmed email address before reporting spam
I have seen your reply for exporting data from comsol to matlab but when I do as u said then I get the following error
Error: 9016
Could not obtain license for SCRIPTPROMPT
License error.
Please login with a confirmed email address before reporting spam
I want to export COMSOL data (maximum von mises stress) in to Matlab. Then I want to compare the value of the maximum von mises stress from the model with an in advanced determined permissible value, to create an optimal geometry for contact lenses. I've less experience with COMSOL and MATLAB interface.
Can someone tell me how to export the specific data to Matlab? In case it's necessary to use my model, I've attached my model.
Thanks in advance!
Arnoud
Attachments:
Please login with a confirmed email address before reporting spam
Did you find out the way to export the vonMises stress per element basis into MATLAB?
My requirement is to do it in V4.1, but not in V3.5a. I know that there are different access methods to interact with the data models in V4.1. For example, I figured out how to get/set domain information on geomety objects. However, the solid mechanis variables appear to be not documented yet.
Best regards,
Kodanda
Please login with a confirmed email address before reporting spam
I didn't discover the way to export the maximum von Mises stress from COMSOL to MATLAB. I've read the document llmatlab_ug.pdf, but it's hard to understand for a MATLAB and COMSOL rookie like me. I'm using COMSOL 4.0a by the way. Do you have any experience with exporting data from COMSOL to MATLAB in COMSOL 4.0a or is it maybe the same as 4.1?
Best regards,
Arnoud
Please login with a confirmed email address before reporting spam
Hi
You need to get your link between COMSOL and Matlab up running, either you missed a step during the installation of COMSOL or some of the files added to matlab are not set up correctly. Have a look at the installation documentation of COMSOL (I beleive ther are other comments in the forum and on the support KB pages).
Once you have the link running, you can (in V3.5a) just do a File "connect" to matlab from the COSOL GUI and export the "fem" structure to Matlab by a CNTRL-F.
then you need to understand the "fem" structure (see mlinterface.pdf in the COMSOL doc) to extract the data in binay mode and you can continue your processing at will.
Good luck
Ivar
Sorry, but this answer does not help.
First of all "when or where" do I have to press ctrl+f. Second I of course want to automatically return values that comsol computes to the matlab script (i.e. without gui ... Matlab calls Comsol and then uses the matrix that comsol produces for further Processing).
Second ... mlinterface.doc - I have not found it and cannot find it. Is it to much to ask for a link if there is a documentation...
The comsol Matlab interface is really a joke. It is a real struggle to do the simplest thing like give a single value from Comsol to Matlab. Sorry, but this is unacceptable.
I hope you will prepare a good solution soon, as I see the necessity to spread this word in the community...
Michael
Please login with a confirmed email address before reporting spam
Hi,
I didn't discover the way to export the maximum von Mises stress from COMSOL to MATLAB. I've read the document llmatlab_ug.pdf, but it's hard to understand for a MATLAB and COMSOL rookie like me. I'm using COMSOL 4.0a by the way. Do you have any experience with exporting data from COMSOL to MATLAB in COMSOL 4.0a or is it maybe the same as 4.1?
Best regards,
Arnoud
Hello,
it need this information too. :)
I want to export only the von Mises stress data calculated in Comsol into Matlab for postprocessing. I know how to export to an txt-file. Of course I can copy paste the whole data, but this is to much handwork.
Greetings
Please login with a confirmed email address before reporting spam
I know this must be a simple operation but how do you export just the eigenvalue/eigenfrequency in the new versions of Comsol? In 3.5a I used "x=fem.sol.lambda;"but now in Comsol 4.2 I have tried different variations of mpheval and mphglobal but have not been able to get the syntax right. Thanks for any assistance.
Please login with a confirmed email address before reporting spam
Hello,
I know this must be a simple operation but how do you export just the eigenvalue/eigenfrequency in the new versions of Comsol? In 3.5a I used "x=fem.sol.lambda;"but now in Comsol 4.2 I have tried different variations of mpheval and mphglobal but have not been able to get the syntax right. Thanks for any assistance.
One way is to reverse engineer things that are not yet documented. For your purpose, there is an "Export Data" node available for the Results section. Right click on the results node and add an Export. There you will be able to select the different native and user-derived variable (if any) as export data. Save the model as an .m file and open it in a text editor, you will see the commands you can use in MATLAB.
best,
Kodanda
Please login with a confirmed email address before reporting spam
I did so as you said.
There are some new lines added to my .m file as follow:
model.result.export.create('data1', 'Data');
model.result.export('data1').set('expr', {'emw.Ex'});
model.result.export('data1').set('descr', {'Electric field, x component'});
model.result('pg1').run;
model.result.export('data1').set('expr', {'emw.Ex' 'lambda'});
model.result.export('data1').set('descr', {'Electric field, x component' 'Eigenvalue'});
But still I dont know what command I should use to get my Eigenvalue or to plot emw.Ex.
Thanks
Please login with a confirmed email address before reporting spam
Hello,
I know this must be a simple operation but how do you export just the eigenvalue/eigenfrequency in the new versions of Comsol? In 3.5a I used "x=fem.sol.lambda;"but now in Comsol 4.2 I have tried different variations of mpheval and mphglobal but have not been able to get the syntax right. Thanks for any assistance.
Hi,
Has a solution for this simple task been found? I am using version 4.3 in comsol.
Thanks,
Hamsa
Please login with a confirmed email address before reporting spam
The solution is posted above by Iman Aryanfar .
Repeat what Iman Aryanfar has did and showed the code. I suggest you to export only one variable while learning the command syntaxes, so you wont get confused.
Best of luck,
Kodanda
Please login with a confirmed email address before reporting spam
model.result.export('data1').set('unit', {'' '' ''});
model.result.export('data1').set('descr', {'Velocity field, x component' 'Velocity field, y component' 'Pressure'});
model.result.export('data1').set('expr', {'u' 'v' 'p'});
model.result.export('data1').set('filename', 'u_v_p.csv');
model.result.export('data1').run;
The last two lines are the most important ones. You have to set the output _and_ run. The above code stores the solution u,v,p to filename 'u_v_p.csv'. The logic is that first you set a bunch of parameters and then you run the export.
After this read the csv file using matlab commands.
Please login with a confirmed email address before reporting spam
With regards to exporting data from COMSOL to MATLAB, we do of course first recommend that you use the LiveLink for MATLAB product for this. Since some of the earlier comments in this thread the documentation has also been expanded with many more examples and code snippets that you will find useful, so please make sure to go through the Introduction to LiveLink for MATLAB documentation and to skim over the LiveLink for MATLAB User Guide, as a lot of the questions here are directly answered therein.
Now, if you have very limited needs and want to and avoid using the LiveLink, you can write out data from the model directly to a text file. Of course there are a number of different formats into which you might like to write the data. This is where the Application Builder will become quite useful. For an example, please see:
www.comsol.com/blogs/exporting-meshes-and-solutions-using-the-application-builder/
Note that you can use the Application Builder within the core functionality of COMSOL Multiphysics, as long as you are running on the Windows platform.
Best Regards,
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.