简体   繁体   English

matlab脚本编辑

[英]matlab script editing

I would like to edit matlab scripts in two cases 我想在两种情况下编辑matlab脚本

(1) In matlab Command window running in a linux terminal, how to create and edit a script file? (1)在linux终端中运行的matlab命令窗口中,如何创建和编辑脚本文件? use 采用

edit(filename)

will invoke the interactive editor, which is not desired while operating on a linux server. 将调用交互式编辑器,这在Linux服务器上运行时是不需要的。

(2) In emacs, is there any way to edit matlab script conveniently? (2)在emacs中,有没有办法方便地编辑matlab脚本? Which is better, using MATLAB-Emacs or EmacsLink? 哪个更好,使用MATLAB-Emacs还是EmacsLink?

when I am trying to cvs checkout MATLAB-Emacs from http://sourceforge.net/scm/?type=cvs&group_id=154105 , which modulename should I specify? 当我试图从http://sourceforge.net/scm/?type=cvs&group_id=154105 cvs checkout MATLAB-Emacs时,我应该指定哪个模块名?

Thanks! 谢谢!


EDIT: 编辑:

When installing MATLAB-emacs, there is some problem. 安装MATLAB-emacs时,存在一些问题。 I thought my CEDET is installed here: 我以为我的CEDET安装在这里:

/usr/share/emacs22/site-lisp/cedet-common   
/usr/share/emacs22/site-lisp/cedet-contrib  

My CEDET is of version 1:1.0pre4-3 (intrepid) on Ubuntu. 我的CEDET在Ubuntu上的版本1:1.0pre4-3(intrepid)。 So I type the command: 所以我输入命令:

$ make "LOADPATH=/usr/share/doc/cedet-common /usr/share/doc/cedet-contrib"    
 for loadpath in . /usr/share/doc/cedet-common /usr/share/doc/cedet-contrib; do \    
       echo "(add-to-list 'load-path \"$loadpath\")" >> autoloads-compile-script; \    
    done;    
 "emacs" -batch --no-site-file -l autoloads-compile-script -f cedet-batch-update-autoloads matlab-load.el .    
 Generatim autoloads for cedet-matlab.el...    
 Generatim autoloads for cedet-matlab.el...done    
 Generatim autoloads for matlab.el...    
 Generatim autoloads for matlab.el...done    
 Generatim autoloads for mlint.el...    
 Generatim autoloads for mlint.el...done    
 Generatim autoloads for semantic-matlab.el...    
 Generatim autoloads for semantic-matlab.el...done    
 Generatim autoloads for tlc.el...    
 Generatim autoloads for tlc.el...done    
 Generatim autoloads for semanticdb-matlab.el...    
 Generatim autoloads for semanticdb-matlab.el...done    
 Updatim header...    
 Updatim header...done    
 Wrote /home/tim/.emacs.d/matlab-emacs/matlab-load.el    
 make: *** No rule to make target `matlab-publish.el', needed by `lisp'.  Stop.    

What's wrong? 怎么了? Thanks! 谢谢!

You should be aware that starting with version R2009a EmacsLink has been removed from Matlab, so I would say that at this point Matlab-Emacs is a better alternative. 你应该知道从版本R2009a EmacsLink开始已经从Matlab中删除了,所以我想说在这一点上Matlab-Emacs是一个更好的选择。 The main strength of EmacsLink was tighter and integration with Matlab, especially when using the debugger, but current version of Matlab-Emacs is quite capable and will probably satisfy most people's needs just as well as EmacsLink. EmacsLink的主要优势是更加紧密并与Matlab集成,特别是在使用调试器时,但当前版本的Matlab-Emacs非常强大,可能会满足大多数人的需求,就像EmacsLink一样。

In order to invoke Emacs from Matlab, the cleanest solution is to run the Emacs server (Mx server-start). 为了从Matlab调用Emacs,最干净的解决方案是运行Emacs服务器(Mx server-start)。 The edit() command can then be set up to open the script in Emacs. 然后可以设置edit()命令以在Emacs中打开脚本。 The detailed instructions on how to do this, as well as on running matlab-shell as inferior process are provided here: 这里提供了有关如何执行此操作以及将matlab-shell作为劣质进程运行的详细说明:

http://blogs.mathworks.com/desktop/2009/09/14/matlab-emacs-integration-is-back/ http://blogs.mathworks.com/desktop/2009/09/14/matlab-emacs-integration-is-back/

Regarding CVS checkout: modulename is "matlab-emacs". 关于CVS checkout:modulename是“matlab-emacs”。 You used to be able to download an archive and simply unpack into your elisp directory. 您以前可以下载存档,只需将其解压缩到elisp目录中即可。

EDIT: I decided to reinstall matlab-emacs; 编辑:我决定重新安装matlab-emacs; here is a step-by-step of what I did. 这是我所做的一步一步。 (The steps are pretty obvious, but this might still be useful seeing how it's easy to run into a compilation error or to misinterpret some instructions). (这些步骤非常明显,但这可能仍然有用,看看如何容易遇到编译错误或误解某些指令)。 Note that matlab-emacs didn't compile until I reinstalled CEDET. 请注意,在我重新安装CEDET之前,matlab-emacs没有编译。

Download CEDET from http://cedet.sourceforge.net/ (1.0pre7 in my case) Uncompress the archive into ~/.emacs.d/elisp/ (now have ~/.emacs.d/elisp/cedet-1.0pre7/ directory) Compile CEDET via make EMACS=/usr/bin/emacs While in ~/.emacs.d/elisp, do the cvs checkout: http://cedet.sourceforge.net/下载CEDET(在我的例子中是1.0pre7)将存档解压缩到〜/ .emacs.d / elisp /(现在有〜/ .emacs.d / elisp / cedet-1.0pre7 /目录)通过make EMACS=/usr/bin/emacs编译CEDET make EMACS=/usr/bin/emacs在〜/ .emacs.d / elisp中,执行cvs checkout:

cvs -z3 -d:pserver:anonymous@matlab-emacs.cvs.sourceforge.net:/cvsroot/matlab-emacs co -P matlab-emacs

Compile matlab-emacs via 通过编译matlab-emacs

make "LOADPATH=../cedet-1.0pre7/common ../cedet-1.0pre7/eieio ../cedet-1.0pre7/semantic/bovine/ ../cedet-1.0pre7/semantic/"

Ideally, everything should compile; 理想情况下,一切都应该编译; now it's time to edit startup files: in the .emacs add 现在是编辑启动文件的时候了:在.emacs中添加

(setq load-path (cons "~/.emacs.d/elisp/matlab-emacs/" load-path))
(load-library "matlab-load")

and in matlab's startup.m add matlab的startup.m中添加

addpath('~/.emacs.d/elisp/matlab-emacs/toolbox','-begin');
rehash;
emacsinit;

That should do it! 应该这样做! Launch emacs, and do Mx matlab-shell. 启动emacs,并执行Mx matlab-shell。 If edit foo.m doesn't open foo.m in emacs, make sure that the server has been launched (Mx server-start). 如果编辑foo.m没有在emacs中打开foo.m,请确保已启动服务器(Mx server-start)。

To be most productive, you might wish to figure out what works for you in terms of sending commands from the edit buffer to matlab process (experiment with the shortcuts in the mode help). 为了最有效率,您可能希望找出在从编辑缓冲区向matlab过程发送命令方面适合您的方法(在模式帮助中尝试快捷方式)。 Finally, if you need to debug stuff, do dbstop in foo , and when you run foo you can either use use dbstop family commands (look them up) or turn on toolbar (Mx tool-bar-mode) and use the buttons there to control breakpoints, stepping, continuing, etc. When finished, type dbquit. 最后,如果你需要调试东西, dbstop in foodbstop in foo ,当你运行foo时,你可以使用use dbstop family命令(查找它们)或打开工具栏(Mx工具栏模式)并使用那里的按钮控制断点,步进,继续等。完成后,键入dbquit。

Unfortunately, if you are on Windows, matlab-shell is not an option (which is a little surprising, seeing how I can run pretty much everything else under the sun from the command line -- Mathematica, R, numpy...) -- so your options for tight emacs/matlab integration are somewhat limited (unless you don't mind running an old matlab version that supports emacslink). 不幸的是,如果你在Windows上,matlab-shell不是一个选项(这有点令人惊讶,看看我如何在命令行下运行太阳下的其他所有东西 - Mathematica,R,numpy ......) - - 所以你对紧密emacs / matlab集成的选择有些限制(除非你不介意运行支持emacslink的旧的matlab版本)。

The matlab-emacs project at http://matlab-emacs.sourceforge.net/ is a slightly more up-to-date version of the Emacs scripts available in the EmacsLink directory that comes with MATLAB. http://matlab-emacs.sourceforge.net/上的matlab-emacs项目是MATLAB附带的EmacsLink目录中提供的稍微更新的Emacs脚本版本。 It is OK to use the matlab-emacs project files with the EmacsLink files that comes with MATLAB. 可以将matlab-emacs项目文件与MATLAB附带的EmacsLink文件一起使用。 The "modulename" is "matlab-emacs". “modulename”是“matlab-emacs”。

I made a blog post about how to use Emacs with MATLAB in more recent versions of MATLAB where the EmacsLink support was dropped. 我发了一篇关于如何在更新版本的MATLAB中使用Emacs和MATLAB的博客文章,其中删除了EmacsLink支持。 You can read it here: 你可以在这里阅读它:

http://blogs.mathworks.com/desktop/2009/09/14/matlab-emacs-integration-is-back/ http://blogs.mathworks.com/desktop/2009/09/14/matlab-emacs-integration-is-back/

The scripts here show how to tweak MATLAB to to use "emacsclient" so that files are pulled up in an already running Emacs. 这里的脚本显示了如何调整MATLAB以使用“emacsclient”,以便在已经运行的Emacs中提取文件。

EDIT: 编辑:

The build system is a bit imperfect with a partial download. 部署下载时,构建系统有点不完善。 The fact that matlab-publish didn't compile is not critical. matlab-publish没有编译的事实并不重要。

The matlab-emacs code from CVS includes a toolbox directory with some M code in it. 来自CVS的matlab-emacs代码包含一个工具箱目录,其中包含一些M代码。 When you run that code, it should setup MATLAB to use emacsclient as the editor. 运行该代码时,应设置MATLAB以使用emacsclient作为编辑器。 I wrote emacsinit.m against the most recent MATLAB, so you may need to edit it with older MATLABs that don't support all features. 我针对最新的MATLAB编写了emacsinit.m,因此您可能需要使用不支持所有功能的旧版MATLAB进行编辑。

To run emacsclient from matlab-shell, the path should be setup automatically, and it should run emacsclient automatically. 要从matlab-shell运行emacsclient,应该自动设置路径,它应该自动运行emacsclient。 If you don't use matlab-shell, you will need to add that directory to your MATLAB path, then call emacsinit. 如果你不使用matlab-shell,你需要将该目录添加到MATLAB路径,然后调用emacsinit。

If it doesn't work for calls to edit, then I'd guess an older MATLAB doesn't have the same configuration features. 如果它对编辑调用不起作用,那么我猜测旧的MATLAB没有相同的配置功能。 You can start MATLAB once with the desktop enabled, and use the Preferences dialog to specify your external editor as emacsclient -n. 您可以在启用桌面的情况下启动MATLAB,并使用“首选项”对话框将外部编辑器指定为emacsclient -n。

The reason that matlab-publish.el does not compile is because in fact it is not downloaded (thus missing) by the MATLAB script dl_emacs_support.m . matlab-publish.el无法编译的原因是因为它实际上没有被MATLAB脚本dl_emacs_support.m下载(因此丢失)。 I also find that the download script also did not download company-matlab-shell.el , which exists in the tarball from CVS. 我还发现下载脚本也没有下载company-matlab-shell.el ,它存在于CVS的tarball中。 Consequently, when make is called, error occurs when the required files are not found. 因此,调用make时,如果找不到所需的文件,则会发生错误。

Even worse, the dl_emacs_support.m script is replaced with the file from CVS when the source files are downloaded by executing the script in MATLAB. 更糟糕的是,当通过在MATLAB中执行脚本来下载源文件时, dl_emacs_support.m脚本将替换为CVS中的文件。 Patches or modifications to dl_emacs_support.m is thus lost after the files are downloaded. 因此,在下载文件后,对dl_emacs_support.m的修补程序或修改将丢失。

To be safe, I recommend to download matlab-emacs from the tarball on the CVS server, or checkout the source. 为了安全起见,我建议从CVS服务器上的tarball下载matlab-emacs,或者检查源代码。 The compilation should go well then. 汇编应该顺利。

Remark about CEDET : I checked out CEDET source code and compile it with no sweat. 关于CEDET的评论 :我查看了CEDET源代码,并且没有任何汗水编译它。 If you are using Ubuntu, I believe the following packages in the repository should be installed before compiling matlab-emacs: cedet-common , ede , eieio , semantic , speedbar . 如果使用的是Ubuntu的,我相信在资源库中的下列软件包应该编制MATLAB的emacs的前安装:CEDET常见义德 ,EIEIO, 语义 ,speedbar。 These packages are installed to /usr/share/emacs/site-lisp , so the LOADPATH should be "/usr/share/emacs/site-lisp/cedet-common /usr/share/emacs/site-lisp/ede /usr/share/emacs/site-lisp/eieio /usr/share/emacs/site-lisp/semantic /usr/share/emacs/site-lisp/semantic/bovine" . 这些软件包安装在/usr/share/emacs/site-lisp ,因此LOADPATH应为"/usr/share/emacs/site-lisp/cedet-common /usr/share/emacs/site-lisp/ede /usr/share/emacs/site-lisp/eieio /usr/share/emacs/site-lisp/semantic /usr/share/emacs/site-lisp/semantic/bovine"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM