Running Comsol from Windows terminal via Matlab script and calling a Matlab function

Please login with a confirmed email address before reporting spam

I want to run Comsol simulations in batch so I want to run it from the terminal. I am using the following command: comsolmphserver matlab -nodesktop -mlnosplash -logfile logfile.log "cd('path\to\m-file'); Honeycomb_sheet; exit"

In the path\to\m-file I have two files: Honeycomb_sheet.m and sigma_wraper.m. Honeycomb_sheet.m is a Matlab script that has all commands to run a Comsol simulation. sigma_wraper.m is a Matlab function that I call within Comsol in the Honeycomb_sheet.m. That is, in Honeycomb_sheet.m I have the following:

model.func.create('extm1', 'MATLAB'); model.func('extm1').set('clearsolve', true); model.func('extm1').set('funcs', {'sigma_wraper' 'solid.el11,solid.el22,solid.el33,solid.el12,solid.el13,solid.el23,i,j'});

However, I cannot run that simulation as I get this error:

Matlab function is not found: sigma wraper - Function: sigma_wraper

I have the file there. I think the issue is that there are two emerging windows as shown in the attached screenshot. By using pwd I noticed that one of the windows has the correct simulation directory but the other widow has the Matlab root directory as the working directory. So because of that, I think it is looking for my sigma_wraper.m in Matlab's root directory.

Is there a way to run a Comsol simulation via a Matlab script that itself calls another Matlab function?



1 Reply Last Post 03.03.2025, 05:01 GMT-5
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 2 months ago 03.03.2025, 05:01 GMT-5

Hi Angel

You have three options: 1) Add the directory where your M-files are placed to the Matlab path and save the path

2) Save your model as an MPH-file in the same directory as the Matlab files before setting uf the function call

3) Add the environmental string COMSOL_MATLAB_PATH to your computer's settings with the value of the directory of your Matlab files. You probably need to restart your terminal window after having made this change

-------------------
Lars Gregersen
Comsol Denmark
Hi Angel You have three options: 1) Add the directory where your M-files are placed to the Matlab path and save the path 2) Save your model as an MPH-file in the same directory as the Matlab files before setting uf the function call 3) Add the environmental string COMSOL_MATLAB_PATH to your computer's settings with the value of the directory of your Matlab files. You probably need to restart your terminal window after having made this change

Reply

Please read the discussion forum rules before posting.

Please log in to post a reply.

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.