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.

Access postprocessed data in Matlab

Please login with a confirmed email address before reporting spam

Hi all,

I'm stuck on a problem somehow. I successfully ran a parameter sweep for a 3D heat transfer model and I trace distribution on one particular line using a 3D cut line. Using the Comsol GUI everything is fine. I can export the data and so on...

I would like to access this data using Matlab for further processing (and tracing more cutlines). I can visualize the solution using mphplot in the form of:

mphplot(model,'pg8');

The different temperature distributions appear for the parameter sweep using Comsols own plot, which is in the plotgroup 'pg8'. So good so far.

How can I access the data for all the parameters (or for one particular parameter)?

Within the .m file the creation of the plotgroup seems to be

model.result.create('pg8', 1);
model.result('pg8').run;
model.result('pg8').set('data', 'cln2');
model.result('pg8').run;
model.result('pg8').feature.create('lngr1', 'LineGraph');
model.result('pg8').feature('lngr1').run;

I could export the data to a file and read it back again, but it would be more nice to access the data without import/export.

Perhaps someone might help me.

Sincerely,
Daniel


4 Replies Last Post Jan 5, 2011, 12:17 PM EST

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 28, 2010, 4:58 AM EDT
if you export the fem from COMSOL to MATLAB, you can see the fem in workspace.

in fem, there are information about mesh, geometry, results(if you export fem after solving) so on.

so just click file> save the workspace in MATLAB.

and then, You can access the data without import/export. Just load the file~.

that's all.;;;;;;;;
if you export the fem from COMSOL to MATLAB, you can see the fem in workspace. in fem, there are information about mesh, geometry, results(if you export fem after solving) so on. so just click file> save the workspace in MATLAB. and then, You can access the data without import/export. Just load the file~. that's all.;;;;;;;;

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 28, 2010, 8:00 AM EDT

if you export the fem from COMSOL to MATLAB, you can see the fem in workspace.


I load the model using mphload. This only returns a name chosen (e.g. "model"). This is the only information I get. The model inspector does not return any information. Btw, I use Comsol 4.0a.


in fem, there are information about mesh, geometry, results(if you export fem after solving) so on.


I can get this information using mpheval, however I don't get the data from the postprocessing plot. However now I could use Matlabs own functions to make an interpolation on a series of lines...

In general my problem is a bit more complicated. I want to trace (using Matlab) several hundred/thousand lines in the 3D space and use the derived data (temperature along the trace) to calculate optical properties etc. Basically I wanted Comsol to do the job tracing my rays and evaluating the temperature on the trace.

But I start to think that it might be more easy and faster to do the interpolation using Matlab.

But thanks a lot for the help!
[QUOTE] if you export the fem from COMSOL to MATLAB, you can see the fem in workspace. [/QUOTE] I load the model using mphload. This only returns a name chosen (e.g. "model"). This is the only information I get. The model inspector does not return any information. Btw, I use Comsol 4.0a. [QUOTE] in fem, there are information about mesh, geometry, results(if you export fem after solving) so on. [/QUOTE] I can get this information using mpheval, however I don't get the data from the postprocessing plot. However now I could use Matlabs own functions to make an interpolation on a series of lines... In general my problem is a bit more complicated. I want to trace (using Matlab) several hundred/thousand lines in the 3D space and use the derived data (temperature along the trace) to calculate optical properties etc. Basically I wanted Comsol to do the job tracing my rays and evaluating the temperature on the trace. But I start to think that it might be more easy and faster to do the interpolation using Matlab. But thanks a lot for the help!

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Nov 12, 2010, 4:57 PM EST
I am having the same difficulty....running COMSOL4.0a with LiveLink for MATLAB

Here's what I can add:

I can use mpheval (From page 96 of the Livelink for MATLAB Manual 4.0a) to get data into a structure where I can see it MATLAB...the trouble is that I have to know the variable name I want to get...I can find out the variable names by using the COMSOL desktop and adding variables to output figures, but I'd like a better way to do this?

Given a model sturcture in is it possible to determine what output variables exist?
Is there documentation someplace that lists the output variables created?

I am having the same difficulty....running COMSOL4.0a with LiveLink for MATLAB Here's what I can add: I can use mpheval (From page 96 of the Livelink for MATLAB Manual 4.0a) to get data into a structure where I can see it MATLAB...the trouble is that I have to know the variable name I want to get...I can find out the variable names by using the COMSOL desktop and adding variables to output figures, but I'd like a better way to do this? Given a model sturcture in is it possible to determine what output variables exist? Is there documentation someplace that lists the output variables created?

Please login with a confirmed email address before reporting spam

Posted: 10 years ago Jan 5, 2011, 12:17 PM EST
Hi all,

I know that in the Matlab Livelink you can extract data at specific boundaries, edges, or points using the "mphinterp" command (See page 137 in the Matlab Livelink User's guide for a description). This command allows you to interpolate the COMSOL solution at any location you desire, even if that coordinate does not correspond to a particular element in the solution. Now, for a parametric sweep like you are discussing, i believe that you can set up a for loop in matlab and run the parametric sweep that way. This way, in the for loop, you can store the information gathered from the mphinterp command in a matrix and postproccess it in any way you'd like.

Hope that helps!

Devin
Hi all, I know that in the Matlab Livelink you can extract data at specific boundaries, edges, or points using the "mphinterp" command (See page 137 in the Matlab Livelink User's guide for a description). This command allows you to interpolate the COMSOL solution at any location you desire, even if that coordinate does not correspond to a particular element in the solution. Now, for a parametric sweep like you are discussing, i believe that you can set up a for loop in matlab and run the parametric sweep that way. This way, in the for loop, you can store the information gathered from the mphinterp command in a matrix and postproccess it in any way you'd like. Hope that helps! Devin

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.