Vim Tips Wiki
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Vim Tips Wiki
1,649
pages
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
Editing
Run Matlab script under Windows
Back to page
Edit
Edit source
View history
Talk (0)
Edit Page
Run Matlab script under Windows
We recommend that you
log in
before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your
Watchlist
.
Creating an account
is quick and free.
The edit appears to have already been undone.
Anti-spam check. Do
not
fill this in!
{{review}} {{TipImported |id=1298 |previous=1297 |next=1299 |created=2006 |complexity=intermediate |author=Manu Hack |version=n/a |rating=1/1 |category1=Matlab |category2=Windows }} If you have a Matlab script file (not function file), then you could add the following simple files to <code>C:/Program Files/Vim/vimfiles/ftplugin/matlab</code> (depends on where you installed Vim). run.py <pre> for i in range(len(vim.current.buffer)): print h.Execute(vim.current.buffer[i]) </pre> run.vim <pre> :py from win32com.client import Dispatch :py import vim :py h=Dispatch('matlab.application') map <buffer> ,r :w<CR>:cd C:/Program Files/Vim/vimfiles/ftplugin/matlab<CR>:pyf run.py<CR> </pre> Then just type <code>,r</code> you can run and get the results in the current windows. Make sure you have a running Python. I'm using WinXP, Vim 7.0, Matlab 6.5, and Python 2.4. See the improved version of this tip in {{script|id=1634}}. ==Comments== Not working. I created the files run.vim, run.py, and the map. However, when I enter a matlab script I get this: <pre> Couldn't open buffer 3 in window 2, creating a new window Error message: NameError: name 'Dispatch' is not defined </pre> ---- Just a thought on this one, perhaps it would be better to enclose run.vim in: <pre> if has("win32") ... endif </pre> just to ensure it doesn't cause problems for those of use who use the same Vim setup on Windows & Linux. Also, it would be beneficial to change the mapping to use $VIM instead of C:\Program Files\vim ---- Another thing is that there should be a tab before the line in the for-loop. You may get an error for omitting that. ---- Some more updates for the code: 1. One may need to add the path where your functions are stored. This can be done by Matlab function addpath. 2. After using for a while, I find that if my script call other functions which have been modified, Matlab is not able to use the updated version of the functions. One could add a line in run.py as follows. run.py <pre> h.Execute("rehash toolboxcache") for i in range(len(vim.current.buffer)): print h.Execute(vim.current.buffer[i]) </pre> Then it should work well. At least at the moment I could start working without going back and forth between Matlab and Vim. ---- Finally got some time to improve the run.vim. Now no need to use the run.py and just put the following run.vim in ftplugin/matlab. <pre> if has("win32") :py from win32com.client import Dispatch :py import vim :py h=Dispatch('matlab.application') :py path=vim.eval('expand("%:p:h")') :py h.Execute("temppath='"+ path+"'") :py h.Execute("addpath(temppath)") :py h.Execute("clear temppath") map <buffer> ,r :w<CR>:py h.Execute("rehash path")<CR>:py print h.Execute(vim.eval('expand("%:t:r")'))<CR> map <buffer> ,b :w<CR>:py h.Execute("rehash path")<CR>:py print h.Execute('dbstop in '+vim.eval('expand("%:t:r")')+' at '+vim.eval('line(".")'))<CR> endif </pre> Still, you need Python with the win32com. Tip: You might want to use 'matlab.desktop.application' for the complete matlab interface. ----
Summary:
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Navigation
(
view source
)
Template:Review
(
view source
)
Template:Script
(
view source
)
Template:TipImported
(
view source
)
Follow on IG
TikTok
Join Fan Lab