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.

Trouble extracting a derived value into Matlab

Please login with a confirmed email address before reporting spam

Hello everyone!

As the title says I got some trouble getting numerical values from my derived values into matlab variables when using the livelink for matlab. What I do is I create a model in comsol, save it as an .m file, turn it into a function and use it in an optimization algorithm. Thus I need to get a comsol derived value into a matlab variable to close the loop.

What I get when I translate the model into an .m file is this:

model.result.numerical.create('av2', 'AvSurface');
model.result.numerical('av2').selection.all;
model.result.numerical('av2').selection.set([2]);
model.result.numerical('av2').set('expr', 'sqrt((mfnc.Br*d(mfnc.Br,r)+mfnc.Bphi*(1/r)*d(mfnc.Br,phi)+mfnc.Bz*d(mfnc.Br,z))^2+(mfnc.Br*d(mfnc.Bphi,r)+mfnc.Bphi*(1/r)*d(mfnc.Bphi,phi)+mfnc.Bz*d(mfnc.Bphi,z))^2+(mfnc.Br*d(mfnc.Bz,r)+mfnc.Bphi*(1/r)*d(mfnc.Bz,phi)+mfnc.Bz*d(mfnc.Bz,z))^2)');

What I want to do is get the value of 'av2' into a matlab variable. I tried using mpheval and mphglobal but it didnt work, not sure if I am using them right.Does anyone have any ideas?

1 Reply Last Post Oct 12, 2013, 7:47 a.m. EDT
COMSOL Moderator

Hello George Kanakaris

Your Discussion has gone 30 days without a reply. If you still need help with COMSOL and have an on-subscription license, please visit our Support Center for help.

If you do not hold an on-subscription license, you may find an answer in another Discussion or in the Knowledge Base.


Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 12, 2013, 7:47 a.m. EDT
I had similar problem and found excelent description at www.rz.uni-karlsruhe.de/~hf118/tutorial_comsol_matlab_livelink.pdf

I think you might try:
model.result.numerical('av2').getReal()

If it doesn't work look into the PDF above

Best
Peter
I had similar problem and found excelent description at http://www.rz.uni-karlsruhe.de/~hf118/tutorial_comsol_matlab_livelink.pdf I think you might try: model.result.numerical('av2').getReal() If it doesn't work look into the PDF above Best Peter

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.