How to/Can I send commands to Matlab remotely

43 views (last 30 days)
I have Matlab running on a computer, and I'm wondering if there is a way to send a command to Matlab from a remote computer. I understand this would require Matlab to open a port and be listening. Aside from writing a thread that runs in the background while Matlab is running, is there capability already in Matlab?
Example:
Matlab started on computer "sim"
Program in "interface" C++ code, independent program on remote computer:
#include "MatlabInterface.h"
int main(int argc,char*argv[])
{
MatlabInterface matlab("sim",PORT_NUMBER);
std::string cmd("a=4");
matlab.sendCommand(cmd);
return 0;
}
where "MatlabInterface" is a class that sets up ethernet socket calls and the "sendCommand" send a string of a certain length over that connection.
Edit:
Long story short, I'd like to run a command in the command window, but the input is an external source, not the Matlab window. Send a message to Matlab that says "Hey Matlab, run this string in your command window."

Answers (2)

Albert Yam
Albert Yam on 18 Jul 2012
What is it that you want to do remotely? If you want total control of Matlab, then just VNC.
If you want to run a script, my first thought was to have a urlread, read something like Etherpad or Evernote, to flip a trigger that is set on a timer function. Not sure if that would work like I imagine.
  1 Comment
Albert Yam
Albert Yam on 18 Jul 2012
urlread reads the page as a string, have some keyword as the trigger (so you can regexp/strfind to find it) and eval the portion of the string after that. (Maybe an end keyword as well).
But I guess that is for shorter/simpler commands. How about uploading an M-file or txt-file to Dropbox/Google drive that you have access to, and urlwrite/run that directly. Start with an empty file, upload one with commands remotely. Not sure how files are saved there, and/or if the url changes.

Sign in to comment.


Jason Ross
Jason Ross on 18 Jul 2012
A few ways I can think if doing this:
  • Parallel Computing Toolbox can have a MATLAB worker running on a remote server. When you submit a command, it runs on the remote machine's MATLAB worker.
  • Instrument Control Toolbox has a way of providing communication over TCP/IP
  • There is a TCP/UDP/IP Toolbox in the File Exchange
  • You could use the iPhone/iPad application and connector to connect back to a MATLAB running on your desktop.
  • Traditional remote control applications: VNC, Remote Desktop
  • If the remote machine is Linux, you can use ssh/rsh to run MATLAB in a terminal shell
There are probably a few others I'm missing or that other people have done/implemented over time. Albert's suggestion of a polling function would also work, with the remote session looking for work on some set interval. Or finding work, generating an m script, then running MATLAB, passing the name of the script to it and returning results.
  2 Comments
Jason Ross
Jason Ross on 23 Jan 2013
The worker that's running remotely is an entirely different process than a MATLAB that would be started on the remote machine, so I don't think they are going to communicate as you would like.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!