How do I return multiple arguments from a MATLAB Excel Builder add-in function?

3 次查看(过去 30 天)
I would like to make an Excel Builder function return two or more output parameters without requiring a separate sub-routine to populate a cell range.

采纳的回答

MathWorks Support Team
To return two or more output parameters, slightly modify the VBA code that is automatically generated by Excel Builder.
For example, if you compile a function FOO into an Excel add-in function, modify the generated VBA code as follows:
Function foo(x1 As Variant, x2 As Variant) As Variant
Dim aClass As Object
Dim y1, y2 As Variant
On Error Goto Handle_Error
aClass = CreateObject("foocomponent.fooclass.1_0")
'Specify the number of outputs as 2, and specify the two output variables
Call aClass.foo(2,y1,y2,x1,x2)
'Create an array from the outputs using the Array function
allouts = Array(y1,y2)
'Return the array
foo = allouts
Exit Function
Handle_Error:
foo = Err.Description
End Function
When executing this function in an Excel worksheet, execute the function as an array function (also known as array formula or CSE formula). This means that you need to make a (horizontal, vertical or area) selection of cells corresponding to the number of output arguments of the function, then you need to press F2 and enter the formula normally. When you have done so, press Ctl+Shift+Enter to confirm the edit. As a result of this, the formula will be displayed by Excel in curly braces {}.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Export to MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by