Is it possible to invoke an instance of Matlab, and run a piece of code using vb.net?
Printable View
Is it possible to invoke an instance of Matlab, and run a piece of code using vb.net?
Lookup the Process component.
VB Code:
Dim myProcess as New Process() myProcess.StartInfo.FileName = "Notepad.exe" myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized myProcess.Start()
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?
Did you use
VB Code:
Imports MatLab
at top of your class or form?
tried it, but it didnt like the Matlab, and it didnt show up as with the other importables like 'System', 'Microsoft', 'MLApp'...
nevermind, i think MLApp is the matlab reference
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
I think you want to pass Nothing in place of Null.
VB Code:
Dim ArrayInput() as Object = new Object(){"surf(peaks)"}
nothing is for vb. null for c,java aand stuff like thatQuote:
Originally Posted by nemaroller
This thread is over two years old. I think everyone who posted to it is either dead or dribbling in an old folks home. :)Quote:
Originally Posted by midhat
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.