Results 1 to 12 of 12

Thread: Matlab Instance

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    124

    Matlab Instance

    Is it possible to invoke an instance of Matlab, and run a piece of code using vb.net?

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Lookup the Process component.

    VB Code:
    1. Dim myProcess as New Process()
    2. myProcess.StartInfo.FileName = "Notepad.exe"
    3. myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
    4. myProcess.Start()

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    124
    I can add a reference to matlab so shouldnt i be able to reference it like an excel object, or any other reference?

    using something like this

    Dim objMatlab as new Matlab.Application
    ....

    however matlab isnt showing up as an available keyword

    i know i can do the process thing, but i want to run matlab from vb, by sending it command lines and having matlab execute them

    any way to do this?

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Did you use
    VB Code:
    1. Imports MatLab

    at top of your class or form?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    124
    tried it, but it didnt like the Matlab, and it didnt show up as with the other importables like 'System', 'Microsoft', 'MLApp'...

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    124
    nevermind, i think MLApp is the matlab reference

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    124
    ok, so i can start an instance of MatLab, however, when i attempt to execute a piece of code i get the following

    "QueryInterface for interface MLApp.DIMApp failed."

    i looked it up on mathworks' webist and they have the following code, but its for VJ...

    using System;
    using System.Reflection;
    namespace ConsoleApplication4
    {
    class Class1
    {
    [STAThread]
    static void Main(string[] args)
    {
    //Get the type info
    Type matlabtype;
    matlabtype = Type.GetTypeFromProgID("matlab.application");

    //Create an instance of MATLAB
    object matlab;
    matlab = Activator.CreateInstance(matlabtype);

    //Prepare input as an object
    object[] arrayInput = new Object[] {"surf(peaks)"};

    //Call MATLAB method
    matlabtype.InvokeMember("Execute",BindingFlags.InvokeMethod,null,matlab,arrayInput);
    }
    }
    }

    I can get everything going except the following

    object[] arrayInput = new Object[] {"surf(peaks)"};

    //Call MATLAB method
    matlabtype.InvokeMember("Execute",BindingFlags.InvokeMethod,null,matlab,arrayInput);

    the null part in the last line is whats giving me trouble, as well as the arrayInput. I dont know how to set a value to null in vb.net since you cant use System.DBNull in an expression, again, any help would be great

  8. #8
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    I think you want to pass Nothing in place of Null.

  9. #9
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB Code:
    1. Dim ArrayInput() as Object = new Object(){"surf(peaks)"}

  10. #10
    Junior Member
    Join Date
    Mar 2006
    Posts
    24

    Re: Matlab Instance

    Quote Originally Posted by nemaroller
    I think you want to pass Nothing in place of Null.
    nothing is for vb. null for c,java aand stuff like that

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Matlab Instance

    Quote Originally Posted by midhat
    nothing is for vb. null for c,java aand stuff like that
    This thread is over two years old. I think everyone who posted to it is either dead or dribbling in an old folks home.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12
    Junior Member
    Join Date
    Mar 2006
    Posts
    24

    Re: Matlab Instance

    lolz sorry. i am new and dint see the date on it. i know how it feels wen some1 does such stuff as i am also a mod somewhere else.

Posting Permissions

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



Click Here to Expand Forum to Full Width