MatLab Automation Server Functions and Properties Feval("load", ...)

14 views (last 30 days)
I am having problems loading a Matlab workspace in VBA - the error I get is that the call to load cannot find "MatLab.mat" which makes no sense as I have provided the filename "reduce_to_common_factors.mat".
Here is my code down to the line which fails:
{Dim m_MatlabApp As Object
Set m_MatlabApp = CreateObject("Matlab.Application")
Dim wkbk As Workbook
Dim wksht As Worksheet
Dim ndim As Integer: ndim = 30
Dim itsdim As Variant
ReDim rho_matrix(1 To ndim, 1 To ndim) As Double
ReDim output(1 To ndim, 1 To ndim) As Double
ReDim my_output_real(1 To ndim, 1 To ndim) As Double, my_output_imag(1 To ndim, 1 To ndim) As Double
Dim image() As Double, my_bool As Boolean, Result As String
Set wkbk = Workbooks("Evaluate_LPI_Swap_30y_With_Smile.xlsx")
Set wksht = wkbk.Worksheets("Modelling_LPI")
Dim cnt_row As Integer, cnt_col As Integer, retVal As Variant
wksht.Activate
'Load the Excel correlation matrix into a double array
For cnt_row = 1 To ndim
For cnt_col = 1 To ndim
rho_matrix(cnt_row, cnt_col) = wksht.Cells(5 + cnt_row, 4 + cnt_col).Value
output(cnt_row, cnt_col) = 0
Next cnt_col
Next cnt_row
'update the workspace variables in MatLab
Result = m_MatlabApp.Execute("cd Q:\Team\Russell_Bickerton\MatLab\Data")
retVal = m_MatlabApp.Feval("load", 0, "reduce_to_common_factors.mat")}
The help topic for this function call is MatLAB, Functions, External Interfaces, MATLAB COM Automation Server Support, MatLAB Automation Server Functions and Properties.

Accepted Answer

Friedrich
Friedrich on 22 May 2013
Edited: Friedrich on 22 May 2013
Hi,
with respect to the IDL signature:
HRESULT Feval([in] BSTR functionname, [in] long nargout,
[out] VARIANT* result, [in, optional] VARIANT arg1, arg2, ...)
I guess this
m_MatlabApp.Feval("load", 0, "reduce_to_common_factors.mat")}
needs to be
m_MatlabApp.Feval("load", 0, Nothing, "reduce_to_common_factors.mat")}
Or maybe instead of Nothing use vbNull. Not sure what you need exactly.

More Answers (0)

Categories

Find more on Write COM Applications to Work with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!