Fortran and matlab
显示 更早的评论
hey all;
I am working on Matlab FE code, and I am suppose to use a fortran code to call my matlab code during some processes.
I am trying to learn now using a simple matlab file ( just simple summation and multplying process), and I use the code: engCallMATLAB to call matlab.
my code ON FORTRAN is:
program Training
implicit none
! Variables
integer*8 ix,z,w,nrhs,nlhs, plhs,prhs,ep,engCallMATLAB
! Body of Training
ix=2
nrhs=1
nlhs=1
z=engCallMATLAB(ep, nlhs, plhs, nrhs, prhs,'Training_M')
w=z-2
print *, w
pause
end program Training
and my matlab simple code is:
clc;
clear all;
ix=2
y=ix^2+3*ix+1;
% u=getu(y);
z=3*y
simply, I need ix to be an input to the matlab code, and and to get z to fortran and then calculate w.
please I am so bad with fortran so if anyone can help I will be so gald.
thanks a lot
Ahmed
采纳的回答
更多回答(2 个)
Ahmed El-Ghandour
2011-11-21
0 个投票
2 个评论
Walter Roberson
2011-11-21
Training.exe corresponds to what the Fortran compiler would generate as your Fortran source contains
Program Training
====
You will need to start your Training_M file with a "function" statement.
There should not be any problem with having your Fortran and MATLAB files in the same folder. Well, there _could_ be problems, but they are the sort of problems that usually take more work to solve than simply putting the files in to different folders.
Ahmed El-Ghandour
2011-11-21
James Tursa
2011-11-21
0 个投票
The engine will need to be opened first using engOpen to get the ep to pass to engCallMATLAB. I assume you are using my engCallMATLAB routine from the FEX since there is no such function in the regular MATLAB API. True? If not, you can find it here (along with an example):
For the .f90 question, you should edit the appropriate engopts.bat file and remove the /fixed option from the compiler options line. I would also do that for the mexopts.bat file as well, btw. That way .f90 files will automatically be interpreted as free form and .f files will be fixed form. As I recall, my engCallMATLAB code will work with either free or fixed form source files, but I will have to go check on that.
2 个评论
Ahmed El-Ghandour
2011-11-29
James Tursa
2011-11-29
Please post your entire sample code so that we can get everything corrected at once instead of piecemeal. Thanks. Do *NOT* include the engine.h file ... that is only for C/C++ apps. Instead, include all of the function type declarations that you use manually (or use my Fortran 95 interface package from the FEX).
类别
在 帮助中心 和 File Exchange 中查找有关 Fortran with MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!