1) Configure Excel sheet
a) Excllink is checked as a Add-In
Tools --> Add-In
Use the correct Excel Link Version related to your MATLAB Version
b) Define Data with a name in Excel:
Write data i.e. into cells A1:A3, mark this area and define a name:
Insert --> Name -> Define type in "DATEN"
c) Open VBA Editor
Tools --> Macro --> Visual Basic Editor
2) CONFIGURE VBA
a) Excllink is checked as a reference
Tools --> References
Search for file "excllink.xla" in your $MATLAB\toolbox\exlink directory, where $MATLAB is your used MATLAB installation directory. The Version of MATLAB and the related Excel Link has to be the same as your add-in in Excel.
b) Insert new Module
Insert --> Module
3) WRITE SUB IN EXCEL VB EDITOR (here based on attached example)
Notes:
- "MLPutMatrix" puts the data into MATLAB workspace
- "MLEvalString" evaluates String in MATLAB, where "matlabtest1" is the MATLAB function in this example
- "MLGetMatrix" write value of variable v into the target cells
Look at the following links for more information about available functions:
Functions - By Category (Excel Link)
<http://www.mathworks.com/help/exlink/functionlist.html>
What the Functions Do :: Getting Started (Excel Link)
<http://www.mathworks.com/access/helpdesk/help/toolbox/exlink/f2-2311.html>
Sub CommandButton1_Click()
MLPutMatrix "data", Range("B3:C6")
MLEvalString "y = data + 1"
MLGetMatrix "y", Range("E3:F6").Address
MatlabRequest
MLEvalString "y1 = data*data'"
MLGetMatrix "y1", Range("B8:E11").Address
MatlabRequest
MLEvalString "y2 = matlabtest1(data)"
MLGetMatrix "y2", Range("B13:E16").Address
MatlabRequest
End Sub
3) Specify macro for button in Excel sheet related to this SUB:
test1.xls!CommandButton1_Click
c) Save everything and try out (push at the button)
Best Answer