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.

Getting derived values into matlab variables

Please login with a confirmed email address before reporting spam

Hello!

I have some trouble getting the value of an average operator into a matlab variable when using comsol through matlab.

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?

Thanks in advance!

3 Replies Last Post 20 nov 2013, 12:22 GMT-5

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 16 mar 2012, 09:37 GMT-4
Hi,
I meet a same problem as you.

What I have done is export the derived value into a txt file, then use the matlab function importdata() to load the value.

I appreciate very much if some one can show the direct method which can read directly the derived value.
Hi, I meet a same problem as you. What I have done is export the derived value into a txt file, then use the matlab function importdata() to load the value. I appreciate very much if some one can show the direct method which can read directly the derived value.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 23 mar 2012, 15:20 GMT-4
Thanks, I ll try that. Still, there should be a more direct way. It seems pretty basic as a need to be complicated as a procedure.
Thanks, I ll try that. Still, there should be a more direct way. It seems pretty basic as a need to be complicated as a procedure.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 20 nov 2013, 12:22 GMT-5
You can put your derived values in table and import the table using mphtable(model, 'tabletag');
This works perfect for Nx2 table but it fails for NxM where M>2. Try and see if this help
You can put your derived values in table and import the table using mphtable(model, 'tabletag'); This works perfect for Nx2 table but it fails for NxM where M>2. Try and see if this help

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.