This a simple matlab wrapper for the SSH toolbox made by David Freedman and published on Matlab Central (LINK)
The wrapper makes it simple to run a local matlab function on a remote machine via an SSH connection, this means you can create, edit and maintain your matlab code on your local machine and export it and its associated variables only at runtime.
The main thing I've used this for is to speed up parfor loops. I manage my matlab code on a laptop with only 2 cores for parallel processing. When there is a machine available with more cores I offload the processing there but keep the code on my machine so I dont need to maintain multiple copies.
What the function does:
- Reads a .mat file that stores your username, passsword (plain text so be careful!), the SSH host address and the matlab run command.
- Finds the file dependencies and variables needed for the function you wish to run and packs them into a zip folder
- Sends the zip to the remote
- Runs the Matlab function using the run command from the .mat file
- Sends the result back as another zip file and loads it into your workspace
- deletes temporary data on remote machine
Edit ssh_default.mat to match your unique setup.
- USERNAME: Change to your username on remote machine
- PASSWORD: Change to your password on remote machine
- sshhost: Name of machine used to connect via ssh
- matlabRunCmd: the command used to start matlab, point to your matlab install path (best to keep the startup flags in example)
Before running send2remote store make sure the necessary variables are saved in a matlab structure with the correct names.
e.g. for some function sorting_script_parfor.m that uses a parfor to speed up processing [sorting_script_parfor(img,vox,sigma,order)]
structtemp.img = img;
structtemp.vox = vox;
structtemp.sigma = sigma;
structtemp.order = order;
[output] = send2remote('sorting_script_parfor',structtemp,'ssh','ssh_machine_name');
Clone git repository and add to Matlab workspace
See "\ssh2_v2_m1_r7\license.txt"