A PUZZLING QUESTION: Does Matlab's Mex file support external inputs and outputs?

1 回表示 (過去 30 日間)
Zhong Hao
Zhong Hao 2014 年 6 月 9 日
コメント済み: Zhong Hao 2014 年 6 月 11 日
Hi, I would like to ask if Mex (Fortran) files are able to use Fortran's OPEN/CLOSE/WRITE/READ from files command?
If yes, how do I implement it in Matlab's Mex files? Else, are there any alternatives to output in an external document?
Thanks
Zhonghao

回答 (1 件)

James Tursa
James Tursa 2014 年 6 月 9 日
Yes, you can use native Fortran file I/O in mex routines. Just write the code as you normally would. The main restriction is in screen I/O ... you can't READ(5,etc) or WRITE(6,etc) in a mex routine as the operations will not work properly. But file I/O is OK.
  5 件のコメント
James Tursa
James Tursa 2014 年 6 月 11 日
編集済み: James Tursa 2014 年 6 月 11 日
Yes, but what is the specific message you see on the screen? Anything? Does anything show up in the Test.txt file?
Zhong Hao
Zhong Hao 2014 年 6 月 11 日
Sorry for the confusion.
An output 'Test.txt' file was created but it is empty. Matlab also crashes when the program was being run.
I've tried compiling and running this on windows 64bit and strangely it works. (by the way, I was using OSX mavericks matlab 2012a with gfortran compiler)
Do you have any idea why this happens?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by