Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 27 Giu 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

Più risposte (0)

Categorie

Scopri di più su Data Export to MATLAB in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by