Java class that calls a Matlab function

Please login with a confirmed email address before reporting spam

Hi,

I am coding my Comsol simulation using Java, i.e., with a Java class. This simulation calls a Matlab function. Additionally, my Java class reads parameters from a text file called 'input.dat'. So I wanted to run this simulation from the terminal with the following command:

comsolbatch -inputfile PiezoLattice.class input.dat

I had successfully run simulations that read data from an input file using the command above. However, for this simulation that calls a Matlab function, I always get the error of not finding the Matlab file. I have placed the Matlab file in the same folder of the Java class and I also tried to place in the Matlab folder (within Documents folder), but in both cases I get the same error. I thought in using the command 'comsolmphserver matlab', I need to use a Matlab file, not the Java class, to use that command.

So, is it possible to have my Comsol simulation that calls a Matlab function in a Java class ?

NOTE: If this discussion is duplicated I posted again because for some reason I could not find my initial post.


1 Reply Last Post 27 août 2025, 15:09 UTC+2
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 hours ago 27 août 2025, 15:09 UTC+2

Hi Angel

let see if I understand this correctly: In the model that is built by running the PiezoLattice.class file you have a MATLAB Function that uses a separate M-file. When looking for the M-file we look in the location of the saved MPH-file. Since there is no MPH-file you need to use one of the other methods of letting Matlab know where your file is. I would set the COMSOL_MATLAB_PATH variable. There is more info here: https://doc.comsol.com/6.3/docserver/#!/com.comsol.help.llmatlab/llmatlab_ug_callback.8.08.html?highlight=comsol_matlab_path

-------------------
Lars Gregersen
Comsol Denmark
Hi Angel let see if I understand this correctly: In the model that is built by running the PiezoLattice.class file you have a MATLAB Function that uses a separate M-file. When looking for the M-file we look in the location of the saved MPH-file. Since there is no MPH-file you need to use one of the other methods of letting Matlab know where your file is. I would set the COMSOL_MATLAB_PATH variable. There is more info here: https://doc.comsol.com/6.3/docserver/#!/com.comsol.help.llmatlab/llmatlab_ug_callback.8.08.html?highlight=comsol_matlab_path

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.