通过Sublime Text 2为MATLAB创建自定义构建系统 [英] Creating custom build system for MATLAB through Sublime Text 2

查看:104
本文介绍了通过Sublime Text 2为MATLAB创建自定义构建系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编辑Sublime Text 2中的.m文件(此问题的其余部分以下简称Sublime)已经有一段时间了,最​​近已经习惯于使用Sublime中的build函数来运行Python代码. ,我试图为MATLAB文件设置类似的内容.我之所以尝试执行此操作,是因为我对在单独的窗口中运行代码和编辑代码感到厌倦.

I have been editing my .m files in Sublime Text 2 (henceforth referred to as Sublime for the remainder of my question) for quite some time now, and having recently become accustomed to using the build function in Sublime for running Python code, I was trying to setup something similar for MATLAB files. I am attempting to do this because I am tired of running my code and editing my code in separate windows.

在阅读文档之后,我尝试使用下面的这段非常合理的代码,其中"-r"标志启动MATLAB来运行我的文件,-nodesktop"标志启动MATLAB,而无需笨拙的Java GUI,而- nosplash"标志会启动MATLAB,而不会出现不必要的启动画面.选择器允许Sublime自动在m个文件上使用此生成系统,并且path变量将路径设置为将启动MATLAB的目录(通过运行哪个matlab"找到的目录).

Following the documentation, I tried using this very reasonable seeming code below, where the '-r' flag launches MATLAB to run my file, the "-nodesktop" flag launches MATLAB without the big hulking Java GUI, and the "-nosplash" flag launches MATLAB without the unnecessary splash screen. The selector allows for Sublime to automatically use this build system on m files, and the path variable sets the path to the directory that will launch MATLAB (directory found by running "which matlab").

我知道我可以在MATLAB GUI中设置首选的文本编辑器,但是我对此并不感兴趣.除了文本编辑器之外,我还有兴趣将Sublime用作构建系统.

I am aware that I can set an preferred text editor from within the MATLAB GUI, but I am not interested in doing that. I am interested in using Sublime as a build system in addition to a text editor.

{
    "cmd": ["matlab", "-r", "-nodesktop", "-nosplash", "$file_name"],
    "selector": "source.m",
    "path": "/usr/local/MATLAB/R2012a/bin"    
}

在我的无错.m文件上运行构建时,我在下面发现此错误,这没有任何意义.我认为这没有任何意义,因为已经使用标准命令行选项启动了MATLAB,并且也收到了MATLAB内部错误.

Upon running build on my errorless .m file, I find this error below, which doesn't make sense. I don't think it makes sense because have launched MATLAB with the standard command line options, and am receiving MATLAB internal errors, too.

/usr/local/MATLAB/R2012a/bin/matlab: 1: /usr/local/MATLAB/R2012a/bin/matlab: awk: not found
/usr/local/MATLAB/R2012a/bin/matlab: 1: /usr/local/MATLAB/R2012a/bin/matlab: expr: not found

Internal error 2: Could not determine the path of the
              MATLAB root directory.

                  original command path = /usr/local/MATLAB/R2012a/bin/matlab
                  current  command path = /usr/local/MATLAB/R2012a/bin/matlab

                  Please contact:

                      MathWorks Technical Support

                  for further assistance.

[Finished in 0.1s with exit code 1]

其他人是否有这样的问题,例如通过备用构建系统调用MATLAB脚本?如果该信息有用,我还没有尝试在Ubuntu 12.04以外的任何其他操作系统上的Sublime中为MATLAB建立构建系统.

Has anybody else had problems like this invoking MATLAB scripts via an alternate build system? I have not tried to set up a build system for MATLAB in Sublime on any other operating system besides Ubuntu 12.04, if that information is useful.

现在可以使用! 这是我的Matlab.sublime-build:

{
    "cmd": ["/usr/local/MATLAB/R2012a/bin/matlab", "-nosplash", "<$file_name"],
    "selector": "source.m"
}

更新:我现在在我的Github页面上托管用于Linux和Mac的Sublime Text 2 R2012a构建文件作为示例: 推荐答案

我是一名出色的新手,但这对我有用.我相信您有两个问题:

I am a sublime newbie, but this worked for me. I believe you have two problems:

  1. 弄清楚如何将PATH环境(Sublime看到的)设置为unix命令提示符的环境.在Mac上,我必须设置一个名为environment.plist的文件并在其中添加路径.这应该摆脱您的awk和expr错误.

  1. Figure out how to set the PATH environment (that Sublime sees) to be that of the unix command prompt. On a mac, I had to setup a file called environment.plist and add the path there. This should get rid of your awk and expr errors.

这是我的matlab.sublime-build:

Here is my matlab.sublime-build:

{ "cmd": ["/Applications/MATLAB_R2011b.app/bin/matlab","<$file_name"] }

{ "cmd": ["/Applications/MATLAB_R2011b.app/bin/matlab","<$file_name"] }

请注意<在$ file_name之前.

Note the < just before $file_name.

这不是完美的:添加nodesktop和nosplash选项会导致错误.就像现在构建脚本一样,该程序在终端中运行正常,但仍然很引人注目.

This isn't perfect: adding the nodesktop and nosplash options lead to errors. As the build script stands now, the program runs fine in the terminal, but I still get the splash.

这篇关于通过Sublime Text 2为MATLAB创建自定义构建系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆