calling Matlab from Fortran using terminal

3 次查看(过去 30 天)
Hi,
My objective is to call a matlab function within a fortran code by using the terminal and not Matlab command window. So, I tried to follow this example: https://www.mathworks.com/help/matlab/matlab_external/build-and-run-fortran-engine-applications-on-linux.html
I executed the command
mex -v -client engine fengdemo.F
in terminal. This creates an executable file called fengdemo
I set the library path using the following command format as mentioned here: https://www.mathworks.com/help/matlab/matlab_external/set-run-time-library-path-on-linux-systems.html
LD_LIBRARY_PATH=matlabroot/bin/glnxa64:matlabroot/sys/os/glnxa64:LD_LIBRARY_PATH
export LD_LIBRARY_PATH
PATH=matlabroot/bin:$PATH
export PATH
After I try to execute fengdemo by typing
./fengdemo
However, I have this error:
./fengdemo: error while loading shared libraries: libmx.so: cannot open shared object file: No such file or directory
I checked that glnxa64 is correctly located in matlabroot/sys/os. I don't know why I get these errors.
And finally, I would like to know how the command
gfortran -o binary_fengdemo fengdemo.F
used for fortran programs not including a call to matlab functions can be adapted for fortran programs including matlab calls.

回答(1 个)

Suvansh Arora
Suvansh Arora 2022-11-11
In order to run MATLAB code within a FORTRAN code by using a Linux Terminal, follow the procedure mentioned below:
  2 个评论
mary
mary 2022-11-11
编辑:mary 2022-11-11
Thank you Suvansh. However, I was aware of those links. I am able to run Fortran and Matlab functions from terminal.
My problem is that fengdemo does not work and I don't know why. I tried to execute a simpler example that is given here: https://www.mathworks.com/matlabcentral/answers/562883-how-do-i-call-use-the-matlab-engine-from-a-fortran-program but I had errors. I would be grateful if you tell me how to solve these errors.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Fortran with MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by