简体   繁体   中英

Calling Matlab from Fortran

I'm trying to run the fengdemo.f using CodeBlocks as my IDE and GNU Fortran Compiler as my compiler. It runs through the include fine but it fails to build any of the method calls to the matlab engine

C:\Program Files\MATLAB\R2012b\extern\examples\eng_mat\fengdemo.F|51|undefined reference to `engopen_'|

C:\Program Files\MATLAB\R2012b\extern\examples\eng_mat\fengdemo.F|58|undefined reference to `mxcreatedoublematrix730_'|

C:\Program Files\MATLAB\R2012b\extern\examples\eng_mat\fengdemo.F|59|undefined reference to `mxgetpr_'|

C:\Program Files\MATLAB\R2012b\extern\examples\eng_mat\fengdemo.F|59|undefined reference to `mxcopyreal8toptr730_'|

C:\Program Files\MATLAB\R2012b\extern\examples\eng_mat\fengdemo.F|64|undefined reference to `engputvariable_'|

etc...

I tried to search online but couldn't really find any helpful info on Mathworks or anywhere else. I've also gotten the c++ engine demo to work so my path variable and other such stuff is correct.

I'm not used to using Fortran at all so any help is appreciated.

PS. The fengdemo.f is under extern/examples/eng_mat so I didn't post any code.

Question: is it even possible without a VFC? And If so can someone point me in the right direction?

You can also do some things "by hand". In Fortran you can use the "system" subroutine to run system commands. For example, if you are in a Linux environment and in a Fortran code you include the command

call system("firefox http://stackoverflow.com/")

the fortran program will open a firefox tab/window to StackOverflow.

You can also use MATLAB from terminal as I read (I don't have it installed). For example, you may call the command below to produce a graph.

matlab -nosplash -nodesktop -r "ezplot('x')" 

So, you may create a matlab function and call it through fortran. Walter Roberson wrote on MATLAB Answers that you can use:

matlab -r 'myfunction(argument1,argument2)';

Or safer:

matlab -r 'try myfunction(argument1,argument2); catch; end; quit'

You can also create an input file with Fortran and use it from MATLAB. This is not an automatic solution, but it does not need a special compiler. But it is platform-depended.

If you're on Windows, the only Fortran compiler supported by MATLAB is Intel Visual Fortran Composer. GNU Fortran is only supported on Linux or Mac.

http://www.mathworks.co.uk/support/compilers/R2013a/index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM