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.

MATLAB LiveLink

Please login with a confirmed email address before reporting spam

Hi!

I am trying to model a smart material called Magnetorheological Elastomers. It can change it's stiffness when a magnetic field is present. To do this, I would like to use a MATLAB function that can calculate the shear modulus based on the field present.

However, I keep running to the issue that the MATLAB directory is not setup correctly... I have gone into MATLAB and set the path directly to where all of the files are located and it still cannot run.

I am using MATLAB 2013a and COMSOL 4.4. I have the read the User Guide for MATLAB LiveLink and I don't understand how to set up the path through the MATLAB command.

"CALLING MATLAB FUNCTION AT THE MATLAB PROMPT
Use MATLAB function to a define model property with the set method:
something.set(property, myfun(<arg>));
where myfun() is a M-function defined in MATLAB.
The function is called only when the command is executed at the MATLAB prompt.
The argument of the function <arg> call be MATLAB variables. To include an
expression value from the model object, you first need to extract it at the MATLAB
prompt, as it is described in Extracting Results.
The function myfun()accepts the model object model as input argument as any
MATLAB variables."

Any help would be appreciated!

Thanks!
Sarah


3 Replies Last Post 30 juin 2014, 15:36 UTC−4

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 29 juin 2014, 09:44 UTC−4
Hi,
it might be the case that you need to set the path to the shared libraries. On a Linux machine this looks like this
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/MATLAB/R2014a/bin/glnxa64
On Windows this should be similar.
Hope that helps.
Best,
Chris
Hi, it might be the case that you need to set the path to the shared libraries. On a Linux machine this looks like this export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/MATLAB/R2014a/bin/glnxa64 On Windows this should be similar. Hope that helps. Best, Chris

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 30 juin 2014, 14:53 UTC−4
Hi Chris!

Thanks for replying. I agree, I think the issue is that the path between the two programs is not set correctly. I am able to open COMSOL with MATLAB and run different kinds of models, except those with functions embedded in the COMSOL model.

Where would I write that line in order for the two programs to be on the same path?

Thanks!
Sarah
Hi Chris! Thanks for replying. I agree, I think the issue is that the path between the two programs is not set correctly. I am able to open COMSOL with MATLAB and run different kinds of models, except those with functions embedded in the COMSOL model. Where would I write that line in order for the two programs to be on the same path? Thanks! Sarah

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 30 juin 2014, 15:36 UTC−4
Hi Sara,
this might be also solved by setting an environmment variable. On Linux machines there is the following command:
export COMSOL_MATLAB_PATH=path_to_my_external_MATLAB_functions
with path_to_my_external_MATLAB_functions being the path to your MATLAB code. Then Comsol server knows where to look for external MATLAX functions. On Windows machine this can by done somewhere in the system settings.
Another option is to use the Set Path in the MATLAB options. Adding only to the MATLAB path via addpath() will not work because Comsol uses a 'clean' new MATLAB instance for external functions.
Best regards,
Chris
Hi Sara, this might be also solved by setting an environmment variable. On Linux machines there is the following command: export COMSOL_MATLAB_PATH=path_to_my_external_MATLAB_functions with path_to_my_external_MATLAB_functions being the path to your MATLAB code. Then Comsol server knows where to look for external MATLAX functions. On Windows machine this can by done somewhere in the system settings. Another option is to use the Set Path in the MATLAB options. Adding only to the MATLAB path via addpath() will not work because Comsol uses a 'clean' new MATLAB instance for external functions. Best regards, Chris

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.