Why do I receive a "Run-time error '9': Subscript out of range" error when passing a matrix to MATLAB using Excel Link?

3 ビュー (過去 30 日間)
I created a matrix in VBA and attempted to pass it into MATLAB in the following way:
Sub MatlabTest()
matlabinit
Dim TestArray(2, 2) As Double
TestArray(0, 1) = 1
TestArray(0, 0) = 1
TestArray(1, 0) = 1
TestArray(1, 1) = 1
mlputvar "MLTestArray", TestArray
End Sub
However, this caused the following error:
Run-time error '9':
Subscript out of range

採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
VBA variables must be 1-indexed in order to be successfully passed to MATLAB via Excel Link. For example:
Dim mldata(1 To 2, 1 To 2) As Double
mldata(1, 1) = 2
mldata(1, 2) = 5
mldata(2, 1) = 6
mldata(2, 2) = 9
'Put variable into MATLAB
MLPutVar "y", mldata

その他の回答 (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