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.

accessing MATLAB global variables when running models in MATLAB

Please login with a confirmed email address before reporting spam

I have defined an external function in matlab that I use in my Comsol/Matlab livelink model to set a volume heat source, let's call this function my_heat(x,y,z), where x,y,z are comsol spatial variables.
Everything works fine with this (comsol passes x,y,z vectors and matlab returns heat source values based on this, and the model is set up and solved)

Now, I tried to use some global MATLAB variables within the 'my_heat' function. When I run function in MATLAB the variables and their values are accessible in 'my_heat'. However, when the same function is called by COMSOL as part of setting the physics, it seems 'my_heat' does not recognize these variables.

I think I know what the problem is, but don't know the solution to it:

When the model is run from Matlab, Comsol seem to open another instance of MATLAB (as manifested by a second command window). This seems like the place where all the Comsol/Matlab interfacing happens. No wonder that in this new instance of Matlab, the information about any global variables in the main Matlab window is missing.
Any ideas on how to 'pass' all the info from the main Matlab window to this auxiliary one?

Thanks,

Robert

P.S.: On an unrelated note, I discovered that by typing 'clear functions' in this new matlab window, I can have comsol get the updated version of any edits to my matlab fuinctions. Without this, comsol only has the first version of external functions. Typing 'clear functrions' in the main matlab window doesn't maker any difference.


4 Replies Last Post 2016年8月15日 GMT-4 20:56
COMSOL Moderator

Hello Robert Furstenberg

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 2012年5月3日 GMT-4 01:52
I have the same problem,
could you find a solution no need for storing data into a file and loading them from m-file function?
I have the same problem, could you find a solution no need for storing data into a file and loading them from m-file function?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2013年12月11日 GMT-5 16:54
I have the same problem now.
Did you finally solve this issue?

Thanks
I have the same problem now. Did you finally solve this issue? Thanks

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2014年2月25日 GMT-5 10:04
Hi,

Was any one of you able to solve this problem? If you could kindly guide me!

Thanks,
Hi, Was any one of you able to solve this problem? If you could kindly guide me! Thanks,

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 2016年8月15日 GMT-4 20:56
You can store the value to a txt file
You can store the value to a txt file

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.