Differences between revisions 3 and 4
Revision 3 as of 2009-04-06 21:04:54
Size: 2298
Editor: anonymous
Comment:
Revision 4 as of 2009-04-06 21:08:45
Size: 2306
Editor: anonymous
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Interface to MatLab =
This interface uses buitin MatLab COM (OLE) Server
= Interface to !MatLab =
This interface uses buitin !MatLab COM (OLE) Server
Line 13: Line 13:
== Do something in MatLab == == Do something in !MatLab ==
Line 37: Line 37:
And MatLab graphics window pops up: And !MatLab graphics window pops up:
Line 43: Line 43:
Initialize APL connection to MatLab COM Server. Initialize APL connection to !MatLab COM Server.
Line 53: Line 53:
Execute MatLab expression and possibly return the result to APL Execute !MatLab expression and possibly return the result to APL
Line 65: Line 65:
Put APL array into MatLab Put APL array into !MatLab
Line 79: Line 79:
Get MatLab variable (matrix or vector) to APL Get !MatLab variable (matrix or vector) to APL

Interface to !MatLab

This interface uses buitin 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:

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

ml2apl (last edited 2009-04-07 08:34:53 by KaiJaeger)