2013-08-07 61 views
1

我有一個Fortran代碼的可執行文件,我想從MATLAB運行。在Linux機器上執行使用intel-fortran編譯的程序

我使用以下兩種方法試過,但得到的錯誤:

!/home/atrac/code case172.jcl 
error:- ls: cannot access ./id: No such file or directory 
ls: cannot access ./id: No such file or directory 

!gnome-terminal --command "./home/myhome/code case12.jcl" 
error: There was an error creating child process for this terminal 

有沒有一種方法,我可以寫一個shell腳本來執行程序,直到執行外部程序,然後暫停Matlab的傳遞控制回Matlab的?

我試圖在Matlab中運行一個遺傳算法,該算法稱之爲外部軟件。 任何想法或幫助,不勝感激。

感謝, 佳日

回答

1

好吧,看起來就像兩個不同的東西會在這裏。兩者都可能與Matlab的當前目錄有關。

!/home/atrac/code case172.jcl 
error:- ls: cannot access ./id: No such file or directory 
ls: cannot access ./id: No such file or directory 

在這裏,它看起來像你管理運行您的程序code,但code或JCL腳本正在尋找一個在當前工作目錄中名爲id文件。當你從Matlab中退出時,這將是Matlab的當前目錄。從Matlab命令提示符運行pwd以找出您的位置。您可以通過在Matlab中使用cd來修復此問題,以移至id文件實際存在的目錄(我猜測它位於/ home/atrac中),然後使用相同的命令行運行code。一個更好的解決方法是重寫code和/或JCL腳本在從任何路徑運行時(可能通過使用絕對路徑)工作,所以你的cwd無關緊要。

!gnome-terminal --command "./home/myhome/code case12.jcl" 
error: There was an error creating child process for this terminal 

在這裏,領先的「。」可能是搞砸了,因爲它現在在當前工作目錄下尋找home/myhome,而不是在根目錄下。嘗試做!gnome-terminal --command "/home/myhome/code case12.jcl"(不帶「。」)。

1

理想的情況下,這應該是一個評論,但我沒有足夠的聲譽。

但是,創建子進程的錯誤與MATLAB無關。 shell正在出錯。你能從終端上運行程序嗎?

其次,您使用的是:

!/home/atrac/code case172.jcl 

,但你應該使用 ./家/ ATRAC /代碼case172.jcl

+0

感謝Lokesh,即使我認爲應該是'!./ home/atrac/code case172.jcl',但那不起作用我得到一個錯誤: /bin/bash:./home/atrac/code:No這樣的文件或目錄 是的我能夠從終端運行這個程序 – user2660994

+0

你能看到什麼是你的Linux的shell? –

+0

另請參閱嘗試運行!ls/home/atrac。這應該列出目錄中的所有文件。這至少會證實目錄是可見的。 –

0

您包含文件夾時,可以從運行MATLAB一個UNIX程序該文件不在MATLAB可見的UNIX系統路徑中。要確定是MATLAB可視系統路徑,鍵入以下命令窗口:

的getenv(「路徑」)

你可以說,持續目前的MATLAB會話或在修改系統路徑隨後的MATLAB會話,如下面的部分所述。

修改當前MATLAB會話的系統路徑。執行以下操作之一:

Change the current folder in MATLAB to the folder that contains the program you want to run. 

Issue these commands using the Command Window: 

path1 = getenv('PATH') 
path1 = [path1 ':/usr/local/bin'] 
setenv('PATH', path1) 
!echo $PATH 

如果重新啓動MATLAB,該文件夾不再位於MATLAB可見的系統路徑中。

http://www.mathworks.com/help/matlab/matlab_env/creating-opening-changing-and-deleting-files-and-folders.html#f0-38522

相關問題