Wikia

Vim Tips Wiki

Run matlab script

Talk0
1,610pages on
this wiki
Revision as of 12:53, July 30, 2012 by 85.178.246.45 (Talk)

I added the following to my .vimrc to be able to run the matlab script under edition usign a single <F5> stroke (with shift-F6 you run Matlab in a terminal):

" The matlab Connection

map <F5> :call MatlabRun()<CR><CR>
map <S-F6> :call RunMatlab()<CR><CR>

func! MatlabRun()
  exec "w"
  exec "!matlab-ctrl.py \"". expand("%:r") . "\""
endfunc

func! RunMatlab()
  exec "w"
  call system("matlab-launch.sh \"" . expand("%") . "\"")
endfunc

I have the following scripts in my $PATH:

matlab-ctrl.py

#!/usr/bin/python2

from subprocess import call 
from subprocess import check_output 
import sys

wcmd = ["xdotool","search","--name","MatlabT"]
w = check_output(wcmd)
w = w.replace('\n','')

if len(sys.argv) > 1:
  s = sys.argv[1]

cmd = ["xdotool","key","--window",w]

for i in range(len(s)):
  cmd.append(s[i])

cmd.append("Return")

call(cmd)

matlab-launch.sh

#!/bin/bash
texfile="$1"
terminal -e "/opt/MATLAB/R2011a/bin/matlab -r clc -nosplash -nodesktop" -T MatlabT --hide-menubar &> /dev/null &
# try to return focus to GVIM
xdotool search --class --name "${texfile}.*GVIM" windowactivate &>/dev/null
exit 0
Advertisement | Your ad here

Around Wikia's network

Random Wiki