Help: Excel Matrix with Buildex EX
3 views (last 30 days)
Show older comments
Hi,
I built an excel add-in with matlab builder ex. The matlab function output is a matrix (Es 100x2) where the number of lines depend on the number of lines in the range input.
I can write the matrix output in a range excel but I don't know how to use such matrix within the VBA subrutine. (I have to do some simple calculation on portion of this matrix and then write the outputs in different ranges).
Could someone help me please? Below the function code in the xlam file and the VBA code in the excel file.
xlam:
Function GRMCOM_SS(Optional DataRng As Variant) As Variant
Dim AugmentedModelParams As Variant
On Error GoTo Handle_Error
Call InitModule
If GRMCOM_SSClass Is Nothing Then Set GRMCOM_SSClass = CreateObject("GRMCOM_SS.GRMCOM_SSClass.1_0") End If
Call GRMCOM_SSClass.GRMCOM_SS(1, AugmentedModelParams, DataRng)
GRMCOM_SS = AugmentedModelParams
Exit Function Handle_Error: GRMCOM_SS = "Error in " & Err.Source & ": " & Err.Description End Function
################# VBA Macro
Sub GRMCOM() Dim R1 As Range 'Input value Dim R2 As Variant 'Output range
On Error GoTo Handle_Error Call InitModule Set R1 = Range(R3) 'Specify where the input value is.
If GRMCOM_SSclass Is Nothing Then Set GRMCOM_SSclass = CreateObject("GRMCOM_SS.GRMCOM_SSclass.1_0") End If Call GRMCOM_SSclass.GRMCOM_SS(1, R2, R1)
?????? How I can storage the output in an array so i can use within this sub and than write the different outpus??
Exit Sub Handle_Error:
'MsgBox ("Error: " & Format(Err.Number) & " Source: " & Err.Source & " Message: " & Err.Description) End If End Sub
Thanks!!
0 Comments
Answers (1)
Kaustubha Govind
on 10 Mar 2011
I don't have much experience with VBA, but according to the documentation on Calling the Methods of a Class Instance:
"When a method has output arguments, the first argument is always nargout, which is of type Long. This input parameter passes the normal MATLAB nargout parameter to the compiled function and specifies how many outputs are requested. Methods that do not have output arguments do not pass a nargout argument. Following nargout are the output parameters listed in the same order as they appear on the left side of the original MATLAB function. Next come the input parameters listed in the same order as they appear on the right side of the original MATLAB function. All input and output arguments are typed as Variant, the default Visual Basic data type."
So, for your code sample, R2 should be the output of the compiled function, and R1 is the input. You should be able to use R2 for further computations.
0 Comments
See Also
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!