Why am I unable to get data from MATLAB into my VBA application?

2 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
I am passing a 1-dimensional Variant array from Excel VBA to MATLAB using the PutWorkspaceData function. This works as expected. However, when I try to read this array back from MATLAB into Excel using the GetWorkspaceData function, I get an error.

採用された回答

MathWorks Support Team
MathWorks Support Team 2016 年 9 月 23 日
When working with data brought in from MATLAB over the COM interface, we need to know the expected dimensions of this object. For instance, in the example below, we need to know that the fromArray returned by MATLAB is a 2x2 matrix:
Sub mytry()
Dim ml As Object
Dim toArray, fromArray As Variant
Dim simple(1, 1) As Double
Set ml = CreateObject("matlab.application")
simple(0, 0) = 1
simple(0, 1) = 2
simple(1, 0) = 3
simple(1, 1) = 4
toArray = simple
Call ml.PutWorkspaceData("toArray", "base", toArray)
Call ml.GetWorkspaceData("toArray", "base", fromArray)
MsgBox fromArray(0, 0) & " " & fromArray(0, 1) & vbCrLf & fromArray(1, 0) & " " & fromArray(1, 1)
End Sub

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Export to MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by