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
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 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