2016-04-19 6 views
2

私の学校のレポートを書くのにorg-modeを使用しています。同じファイルにいくつかのMatlabコードを含めることができるので非常に便利です。 しかし、問題は、Matlabが関数を別のファイルで宣言する必要があるため、新しい関数を定義することができないことです。orgモードで同じファイルにmatlab関数を定義する方法

これは、中央ファイルを1つしか変更できないため、非常に不便です。

+0

コードブロックでそれを使用しています。 1つのファイル内に複数の機能を持たせることができ、外部からアクセスできないだけです。彼らは[ローカル関数](http://www.mathworks.com/help/matlab/matlab_prog/local-functions.html?refresh=true)と呼ばれています – Suever

+0

@Suever、あなたは正しいですが、結局私は作成を避けたいと思います一緒に新しいファイル。おそらくorgモードで新しいファイルをシミュレートする方法がありますか? – maroxe

答えて

1

これは私のために入れ子関数を使用して動作します。出力は醜いですが、ここにはファイルが作成されていません。Matlabに送信されるコードブロックだけです。 (これはMacOSXとLinuxで動作しますが、以前はWindowsで動作しませんでした。

#+BEGIN_SRC matlab 
function parent 
disp('This is the parent function') 
nestedfx 

    function nestedfx 
     disp('This is the nested function') 
    end 

end 
#+END_SRC 

#+RESULTS: 
#+begin_example 

          < M A T L A B (R) > 
        Copyright 1984-2013 The MathWorks, Inc. 
        R2013a (8.1.0.604) 64-bit (maci64) 
          February 15, 2013 


To get started, type one of these: helpwin, helpdesk, or demo. 
For product information, visit www.mathworks.com. 

>> >> This is the parent function 
>> >> >> >> This is the nested function 
>> >> >> >> 
#+end_example 

外部機能を使用するには、使用しないでください。まず、関数を定義します。

#+BEGIN_SRC matlab :tangle myfunc.m 
function myfunc 
    disp('External function') 
end 
#+END_SRC 

この次のブロックは、mファイルを引き出します。

#+BEGIN_SRC emacs-lisp 
(org-babel-tangle) 
#+END_SRC 
#+RESULTS: 
| myfunc.m | 

今、私たちは、これは真実ではありません

#+BEGIN_SRC matlab 
myfunc() 
#+END_SRC 

#+RESULTS: 
#+begin_example 

          < M A T L A B (R) > 
        Copyright 1984-2013 The MathWorks, Inc. 
        R2013a (8.1.0.604) 64-bit (maci64) 
          February 15, 2013 


To get started, type one of these: helpwin, helpdesk, or demo. 
For product information, visit www.mathworks.com. 

>> External function 
>> 
#+end_example 
関連する問題