Avatar of chspit
chspit

asked on 

Controlling matlab from VB.NET

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.
.NET Programming

Avatar of undefined
Last Comment
ptakja
Avatar of Mikal613
Mikal613
Flag of United States of America image

Avatar of ptakja
ptakja
Flag of United States of America image

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.

Avatar of chspit
chspit

ASKER


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).
ASKER CERTIFIED SOLUTION
Avatar of ptakja
ptakja
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo