Solved

Controlling matlab from VB.NET

Posted on 2004-04-01
4
969 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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 video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

724 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