= Interface to MatLab = <> This interface uses builtin !MatLab COM (OLE) Server == Sample APL Session == {{{ )load r2apl d:\r2apl saved Mon Apr 06 22:10:59 2009 mlinit ⍝ initialize connection to MatLab COM server )obs ⍝ new object MatLab is created MatLab mlput 2 3⍴⍳6 ⍝ put APL matrix to MatLab }}} == Do something in MatLab == {{{ » X X = 1 2 3 4 5 6 » sum(X) ans = 5 7 9 » s=sum(X); » }}} == Back to APL == {{{ mlget 's' 5 7 9 mlexec 'surf(peaks)' }}} And !MatLab graphics window pops up: {{attachment:surf.png}} == Dyalog APL functions == === mlinit === Initialize APL connection to !MatLab COM Server. {{{ ∇ mlinit [1] ⍝ version for ⎕SE [2] '#.MatLab'⎕WC'OleClient' 'Matlab.Application' [3] 2 ⎕NQ'#.MatLab' 'SetMethodInfo' 'PutFullMatrix'(('' 'VT_VOID')('Name' 'VT_BSTR')('Workspace' 'VT_BSTR')('pr' 'VT_ARRAY of VT_R8')('pi' 'VT_ARRAY of VT_R8')) ∇ }}} === mlexec === Execute !MatLab expression and possibly return the result to APL {{{ ∇ {a}←mlexec exp [1] ⍝ Execute MatLab expression and convert char2num [2] ⍝R: MatLab expression ('char') [3] ⍝e: mlexec 'surf(peaks)' [4] ⍎(';'≠¯1↑exp)/'exp←exp,'';''' [5] a←#.MatLab.Execute exp ∇ }}} === mlput === Put APL array into !MatLab {{{ ∇ {m}mlput a;x1 [1] ⍝ Version for ⎕SE [2] ⍝ Put APL array to MatLab [3] ⍝R-name of variable to export from APL [4] ⍝L-name of variable to create in MatLab [5] ⍎(0=⎕NC'm')/'m←''X''' ⍝ Default [6] #.MatLab.PutFullMatrix m'base'a 0 [7] a←#.MatLab.Execute m,'=real(',m,');' ∇ }}} === mlget === Get !MatLab variable (matrix or vector) to APL {{{ ∇ r←mlget x;rho;Re;Im;⎕ML [1] ⍝ version for ⎕SE [2] ⍝ Get MatLab matrix to APL [3] ⍝L-name of variable to import ('char') [4] ⎕ML←3 [5] rho←#.MatLab.Execute'size(',x,')' [6] rho←1↓(~rho∊⎕TC)⊂rho [7] rho←{⍎¨(⍵≠' ')⊂⍵}¨rho [8] rho←∊rho [9] Re←rho⍴0 ⍝ Protorype variable [10] Im←0 [11] r←↑#.MatLab.GetFullMatrix x'base'Re Im ∇ }}} Author: AlexanderSkomorokhov 2009-04-06 ---- CategoryTechnologies