Why do I receive a "Run-time error '9': Subscript out of range" error when passing a matrix to MATLAB using Excel Link?
1 view (last 30 days)
Show older comments
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
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
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 Comments
More Answers (0)
See Also
Categories
Find more on Data Export to MATLAB 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!