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.

set path of the external matlab function

Please login with a confirmed email address before reporting spam

Hello all,

I am trying to run a Matlab script of my model which in turn uses an external Matlab function. When I run the model from matlab, comsol opens a new Matlab process and tries to call the function. the problem is I am not able to explicitly specify the path of the function being called.

I did add the function's path to Matlab path, but it somehow does not get updated in the new process that comsol opens internally.

Going through Java API documentation, I found that it is possible to set the path of the function using

model.func.create('extm1', 'MATLAB');
model.func('extm1').set('funcs',{<functionname>,<argslist>});
model.func('extm1').set('manpath',<path>)

This however, does not seem to work from Matlab. Any ideas, suggestions?

Also, when I copied the function in Matlab's default path (/home/user/Documents/MATLAB), the script works just fine, it only doesnt work when the path is not default

1 Reply Last Post 27 mars 2013, 04:07 UTC−4
Remi Magnard COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 27 mars 2013, 04:07 UTC−4
Dear Jyani,

To set up the function directory path in MATLAB you have three options:
- save the model (in the MPH format) in the same directory as the for the M-functions. In case you set up the model in a M-file, you can still save the model object before running the study. To proceed add the command:
model.save(fullfilename);
- Set the system environment variable COMSOL_MATLAB_PATH with the M-functions directory path.
- Use the Set Path window available in the MATLAB desktop (MATLAB Home ribbon > Environment group). Adding the MATLAB path (with ADDPATH) does not as you the external MATLAB function is evaluate in a separate MATLAB process.

The JAVA API reference guide refers to an obsolete properties, sorry for the confusion.

Best regards,

Rémi Magnard
Dear Jyani, To set up the function directory path in MATLAB you have three options: - save the model (in the MPH format) in the same directory as the for the M-functions. In case you set up the model in a M-file, you can still save the model object before running the study. To proceed add the command: model.save(fullfilename); - Set the system environment variable COMSOL_MATLAB_PATH with the M-functions directory path. - Use the Set Path window available in the MATLAB desktop (MATLAB Home ribbon > Environment group). Adding the MATLAB path (with ADDPATH) does not as you the external MATLAB function is evaluate in a separate MATLAB process. The JAVA API reference guide refers to an obsolete properties, sorry for the confusion. Best regards, Rémi Magnard

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.