Solved

Controlling matlab from VB.NET

Posted on 2004-04-01
4
950 Views
Last Modified: 2007-12-19
Hi,

I want to start Matlab, then run an m-file automatically.
Below is what I've done so farin VB.NET.

__________________________________________________________________________
Shell("C:\MATLAB6p5\bin\win32\matlab.exe", AppWinStyle.MaximizedFocus)
        Thread.Sleep(20000)

       SendKeys.SendWait("m-file")
        SendKeys.SendWait("{ENTER}")
__________________________________________________________________________

I had to use 'sleep' to wait for Matlab to load completely before sending keys, otherwise nothing will happen.

The question is: is there a command instead of 'sleep' that knows when the application has loaded and is ready to receive keystrokes?
Also, I want matlab to quit automatically after the m-file has been run. How can I do that?

Thanks in advance for your help.
0
Comment
Question by:chspit
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 10732313
0
 
LVL 14

Expert Comment

by:ptakja
ID: 10732932
Instead of using the Shell command, check out the Process component.

To start MatLAB, for example, you could enter:

Process.Start("C:\MATLAB6p5\bin\win32\matlab.exe")

I am not a MatLAB person, but I believe you can pass the m-file to Matlab on the command line.  Check out this link at MathWorks website.  It shows the syntax to do this:  http://www.mathworks.com/support/solutions/data/36616.html

Once you execute the Process.Start method, you could call the Process.WaitForInputIdle method to wait for MatLAB to get into a state where it is waiting for operator input.

Finally, call Process.Kill to stop MatLAB.

Check into the Process component in the .NET Framework.  This component gives you alot of remote control of a process from your application.

0
 

Author Comment

by:chspit
ID: 10734659

Mikal613,

The link you gave explains how to wait for a program to end before continuing with the
processing.
However, what I wanted was a command that does not allow the SendKeys command to be executed before an application loads entirely (i.e. when an application, such as matlab, is ready to receive keystrokes after it has been instantiated).
0
 
LVL 14

Accepted Solution

by:
ptakja earned 125 total points
ID: 10736598
In that case just execute the Process.Start method as shown above and then call the Process.WaitForInputIdle method.  When that method returns, MatLAB should be up and running waiting for user input.  At that point you could then execute the SendKeys function(s).
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now