Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Piscataway, New Jersey, USA
    Posts
    171
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pass argument to Matlab via automation (Access 2002 sp 2)

    Hi Everybody:

    I've written an Access app that does a bunch of stuff and exports data to Excel worksheets. My boss has written a Matlab program to process the data from Excel. Now, we want to put them together.

    I would like to use my Access user form to run his Matlab m file, because the eventual user will need Access to update the data, select the workbook, etc. I can automate Matlab, but am stumped as to how to pass it a variable as an argument.

    My m file is a function that takes varargin. It works fine from Matlab, but when I try to pass the path to the Excel workbook from my Access VBA project, I get a Matlab error: 'Undefined function or variable strInput'.

    Here's the (really simple) code:

    Sub RunML()
    Dim MatLab as object, strInput as string, Result
    strInput = fnGetXLFilePath() 'Opens Explorer and returns user selected full path and file name as a string
    Set MatLab = CreateObject("MatLab.Application")
    Result = MatLab.Execute("ProcessXL(strInput)")
    Debug.print Result
    MatLab.Quit
    Set Matlab = nothing
    end sub

    This works fine as long as I don't try to pass an argument, but Matlab doesn't seem to understand when I do.

    The m file starts like this:

    function ProcessXL(varargin)
    %where varargin is the path to the Excel file.


    Anyone know how to fix it?

    Thanks!

    P.S. No, he doesn't want to use ExcelLink

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Pass argument to Matlab via automation (Access 2002 sp 2)

    I don't know anything about Matlab, so the following is pure guesswork.
    Try the following
    <code>
    Result = Matlab.Execute("ProcessXL(" & Chr(34) & strInput & Chr(34) & ")")
    </code>
    This assumes that the Matlab function expects a string delimited by double quote characters <code>"</code>. If it expects single quotes <code>'</code> around the string, change both instances of Chr(34) to Chr(39).

  3. #3
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Piscataway, New Jersey, USA
    Posts
    171
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pass argument to Matlab via automation (Access 2002 sp 2)

    Thanks, Hans. You were right that string delimiters were the problem.

    Solution:

    strCommand = "ProcessXL('" & strInput & "')"
    Result = MatLab.Execute(strCommand)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •