How to pass a matrix input argument to a VBA function generated by MATLAB Builder EX?

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)

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

Sorry i was unable to find a solution to my problem from the link. i tried looking for the line where the example vba code calls the matlab function with a vector as a parameter. i found the line but could not understand. Thanks for your help.

Sign in to comment.

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

Asked:

on 27 Aug 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!