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.

COMSOL 4.1 and LiveLink MATLAB R2010b

Please login with a confirmed email address before reporting spam

Ok, I am really confused and somewhat frustrated by how difficult it seems to read results in MATLAB from a COMSOL solution.

I could easily export my result in a text file directly from COMSOL and then do calculations in Excel but that would defeat the purpose of using my calculations results back in COMSOL!

What I did in COMSOL:
- Linear Graph of a 1D Plot Group to get the temperature profile on a edge (Data Set named "Edge 2D 1") of a 2D geometry (this look like attachment #1).

What I'm trying to do: Calculate the STANDARD DEVIATION of the temperature profile on that edge (for further modification of geometric parameter to optimize it).

What I have been TRYING to do in MATLAB:
- Get the temperature values on my edge by using (after exporting my model from COMSOL to the COMSOL server):

[myTemp] = mphinterp(model, ['T'], 'dataset', 'edg1')

That doesn't work, it gives me data for half of my edge and afterwards it's all over the place (see attachment #2) (I guess I would need to sort out my values but why isn't it following the arc length?)

I also tried:

myTemp = mpheval(model, 'T', 'edim', 1, 'selection', 3)

which gives me a structure which contains my temperature data but once again my data are all scrambled up when I try to plot them (see attachment #2)

Any ideas why this is so scrambled up? I just want to calculate the Standard Deviation which shouldn't be that hard!

Where is the "LiveLink" in there? I don't see any bidirectional capabilities and surely not "seamless integration" as it was suppose to be... :(


11 Replies Last Post Feb 29, 2012, 11:48 a.m. EST

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 30, 2011, 3:47 a.m. EDT
Hi Dominique,


What I have been TRYING to do in MATLAB:
- Get the temperature values on my edge by using (after exporting my model from COMSOL to the COMSOL server):

[myTemp] = mphinterp(model, ['T'], 'dataset', 'edg1')

That doesn't work, it gives me data for half of my edge and afterwards it's all over the place (see attachment #2) (I guess I would need to sort out my values but why isn't it following the arc length?)

I also tried:

myTemp = mpheval(model, 'T', 'edim', 1, 'selection', 3)

which gives me a structure which contains my temperature data but once again my data are all scrambled up when I try to plot them (see attachment #2)

Any ideas why this is so scrambled up? I just want to calculate the Standard Deviation which shouldn't be that hard!



I'm sorry I don't have a solution, but I have exactly the same problem with my model. I just want the data that COMSOL plots in Matlab to edit it.


Have you solved it yet?

Regards,

Peter.

Hi Dominique, [QUOTE] What I have been TRYING to do in MATLAB: - Get the temperature values on my edge by using (after exporting my model from COMSOL to the COMSOL server): [myTemp] = mphinterp(model, ['T'], 'dataset', 'edg1') That doesn't work, it gives me data for half of my edge and afterwards it's all over the place (see attachment #2) (I guess I would need to sort out my values but why isn't it following the arc length?) I also tried: myTemp = mpheval(model, 'T', 'edim', 1, 'selection', 3) which gives me a structure which contains my temperature data but once again my data are all scrambled up when I try to plot them (see attachment #2) Any ideas why this is so scrambled up? I just want to calculate the Standard Deviation which shouldn't be that hard! [/QUOTE] I'm sorry I don't have a solution, but I have exactly the same problem with my model. I just want the data that COMSOL plots in Matlab to edit it. Have you solved it yet? Regards, Peter.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 30, 2011, 11:19 a.m. EDT
Hi,

I'm also confronting the similar problem, confused with the postprocess.
Anyone can help?
Hi, I'm also confronting the similar problem, confused with the postprocess. Anyone can help?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 30, 2011, 11:26 a.m. EDT
I haven't work on that since, been busy with something else.
I will need to get back on it, so if I find out anything, I'll keep you posted.

Good luck finding your way in MATLAB "LiveLink"....
I haven't work on that since, been busy with something else. I will need to get back on it, so if I find out anything, I'll keep you posted. Good luck finding your way in MATLAB "LiveLink"....

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 30, 2011, 2:16 p.m. EDT
Well, the LiveLink itself isn't that hard to get to know. Just don't forget to click "File" > "Reset History" before saving your .mph files as .m file.This makes your code a lot less messy.
Well, the LiveLink itself isn't that hard to get to know. Just don't forget to click "File" > "Reset History" before saving your .mph files as .m file.This makes your code a lot less messy.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 30, 2011, 2:19 p.m. EDT
Yep, that's a good point (resetting the History).

But right now I'm still stuck at the point where I can modify a file that I converted into a .m file but I am not yet able to reconvert a .m into a .mph file...
Yep, that's a good point (resetting the History). But right now I'm still stuck at the point where I can modify a file that I converted into a .m file but I am not yet able to reconvert a .m into a .mph file...

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 30, 2011, 2:22 p.m. EDT
After modifying your model in Matlab use (not sure about the exact syntax, no COMSOL on my laptop):
model.save('myModel.mph');
After modifying your model in Matlab use (not sure about the exact syntax, no COMSOL on my laptop): model.save('myModel.mph');

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 30, 2011, 2:52 p.m. EDT
Yes, that's for saving it back into the COMSOL server.

My problem is:
- If I send a file through the COMSOL server from COMSOL to MATLAB, I don't know how to save that file in MATLAB as a .m file. (model.save does not allow that).

So the only way I found to have a .m file is to directly in COMSOL, save as MATLAB .m file.
Once I do that, I can open the file in MATLAB without problem and edit it BUT I can't sent it back into COMSOL nor the COMSOL server since there is no way to read a .m file into the MPH model class (if there is, I haven't found one).
Yes, that's for saving it back into the COMSOL server. My problem is: - If I send a file through the COMSOL server from COMSOL to MATLAB, I don't know how to save that file in MATLAB as a .m file. (model.save does not allow that). So the only way I found to have a .m file is to directly in COMSOL, save as MATLAB .m file. Once I do that, I can open the file in MATLAB without problem and edit it BUT I can't sent it back into COMSOL nor the COMSOL server since there is no way to read a .m file into the MPH model class (if there is, I haven't found one).

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 6, 2011, 3:16 p.m. EDT
That is my question too: How to send back the edited .m file to Comsol.
That is my question too: How to send back the edited .m file to Comsol.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 11, 2011, 8:32 a.m. EDT
see my thread 'convert .m to .mph'!
see my thread 'convert .m to .mph'!

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 4, 2011, 9:59 p.m. EDT
Try this for getting temperature at any point from matlab m file:

Compute the temperature T at the center of the domain:
T = mphinterp(model,'T','coord',[0.3;0.5])

This command "mphinterp" has replaced "postinterp" in Comsol 3.5a. Hope this helps.
Thanks.
Try this for getting temperature at any point from matlab m file: Compute the temperature T at the center of the domain: T = mphinterp(model,'T','coord',[0.3;0.5]) This command "mphinterp" has replaced "postinterp" in Comsol 3.5a. Hope this helps. Thanks.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 29, 2012, 11:48 a.m. EST
Hi everyone,

I have a similar problem with mphinterp...

I have a 2D model, on wich I have used the Heat Transfer module in a transient study. I want to read and save the temperature evolution in a point I have defined in the center of my domain, but I don't want to call it by its coordinates. That is, I want to "call" that point by its tag.

So lets say this point is number 3. I do the following:

[Temp] = mphinterp(model,'T','Edim',0,'selection',3);

I get this error:

??? Error using ==> mphinterp at 144
Coordinate or non-solution dataset is required

I am using the COMSOL version 4.2a

Have you solved your problem? Do you have any ideas about what I am doing wrong?

Thank you!

Ana Gaspar
Hi everyone, I have a similar problem with mphinterp... I have a 2D model, on wich I have used the Heat Transfer module in a transient study. I want to read and save the temperature evolution in a point I have defined in the center of my domain, but I don't want to call it by its coordinates. That is, I want to "call" that point by its tag. So lets say this point is number 3. I do the following: [Temp] = mphinterp(model,'T','Edim',0,'selection',3); I get this error: ??? Error using ==> mphinterp at 144 Coordinate or non-solution dataset is required I am using the COMSOL version 4.2a Have you solved your problem? Do you have any ideas about what I am doing wrong? Thank you! Ana Gaspar

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.