Open matlab in fortran environment

3 visualizaciones (últimos 30 días)
Thales
Thales el 23 de Mzo. de 2015
Editada: James Tursa el 23 de Mzo. de 2015
I'm working with Fortran and I would like to open Matlab to plot my answers. How to do it? The compiler is Intel Visual Fortran.
I'm working with really large arrays (10^8-10^9 columns and 10-100 rows), so I would like to avoid saving the numbers in a file and opening them in matlab. Is there anyway to open directly the matlab in fortran and plot the results?

Respuestas (1)

James Tursa
James Tursa el 23 de Mzo. de 2015
Editada: James Tursa el 23 de Mzo. de 2015
The general advice here is
1) Have MATLAB call your Fortran code as a mex routine, and then use the mexCallMATLAB function inside your Fortran code to call back to MATLAB for the functions you want. This is the easiest way to call MATLAB functions (and get the results back into your Fortran code if desired). Your Fortran code is actually a DLL for MATLAB and shares the same address space as MATLAB. The downside is you may need to re-architecture some of your code (e.g., I/O) to get it to work as a mex function, and it can be a little more difficult to debug your Fortran code, but can be done. You will need to copy your Fortran data into MATLAB variables to do the plotting.
2) Have your Fortran code call MATLAB as an Engine application. MATLAB actually starts as a separate process (does not share the same address space with your Fortran code) so variables have to be copied back & forth to get the function calls done. So fewer changes will be needed for your Fortran code to go this route, but more cumbersome and generally less efficient than the mex function route for the MATLAB function calling part, and probably easier to debug your Fortran code.
Information and examples can be found here:
Note that in both cases a data copy is involved. The data copy can be avoided in method (1) above if you use MATLAB allocated memory for all of your variables that need plotting, but it is not trivial to do this. Explanation of this method can be found in this FEX submission:

Categorías

Más información sobre Fortran with MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by