Search code examples
c#linuxmatlabremote-accessmatlab-deployment

How do I remote call MATLAB software on a Linux server from a C# desktop program on Windows?


I code a C# desktop program on windows and some matlab programs on a linux server.How could I achieve — select local data using the C# program and then transfer the data to the matlab programs.After the data processed on the linux server,the results will be sent to the C# desktop program? Answer Request


Solution

  • I would start by trying the following 'recipe'. First make sure you have ssh access to the server.

    1. Save your data from C# to a file in a Matlab-friendly format, I recommend binary but text file is also ok.
    2. Copy the data to the server, using some scp client like WinSCP. This could be done from C# using the Process class to send command-line execution command.
    3. Send a remote call to your Matlab program, from C# using some SSH library (I am not familiar with C# but I am sure it's possible). You might find the Matlab startup option -r useful, to start Matlab and call a script.
    4. Make sure the Matlab code saves the results to the disk.
    5. To get the results back to your local machine, you could again copy it from the remote server using scp, the easiest thing to do is to try and copy it inside a loop until the copying succeeds, with some pause between tries, and an upper limit of the time (in case something goes wrong on the server side, you wouldn't want to wait forever). If you want to make it less 'dirty', you could establish a tcp client-server connection between the remote and local machine, and have the remote machine send a message once the file is ready for copying. You could even get the data over tcp, instead of saving to file, if it's not too much data.