How to pass a matrix input argument to a VBA function generated by MATLAB Builder EX?
Show older comments
Hi. I have a function whose definition is as follows:
function y=perm(A)
where A is a square matrix.
I used MATLAB Builder EX to generate a .bas file for the same. The vba code has InitModule() and another function as follows:
Function perm(Optional A As Variant) As Variant
Dim y As Variant
On Error GoTo Handle_Error
Call InitModule
If perm_class Is Nothing Then
Set perm_class = CreateObject("GraphTheory.perm_class.1_0")
End If
Call perm_class.perm(1, y, A)
perm = y
Exit Function
Handle_Error:
perm = "Error in " & Err.Source & ": " & Err.Description
End Function
I want to read a Matrix from a range of Excel Worksheet cells and pass a matrix to this function. How do i do it? I tried to make a 4x4 array in VBA like
Dim X(4,4) as Double
But i get error.
Please help.
Regards,
Amit Singh
Answers (2)
Kaustubha Govind
on 29 Aug 2011
0 votes
I'm not all too familiar with calling MATLAB Builder EX components from VBA, but I thought this documentation example may help you: Building and Integrating a COM Component Using Microsoft Visual Basic: the Spectral Analysis Example.
1 Comment
Amit Singh
on 29 Aug 2011
Anh
on 3 Nov 2011
0 votes
Yes you can. The best way to see how to pass a range from Excel to the function is to used Matlab Builder EX Function Wizard. You can use it to specify an input range for your function, and generate a macro code.
Hope it helps.
Categories
Find more on Excel Add-Ins in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!