Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Controlling matlab from VB.NET

Posted on 2004-04-01
4
Medium Priority
?
999 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 375 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 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