windows cmd上的Matlab(winxp)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/739409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Matlab on cmd (winxp)
提问by Rook
I've just started experimenting something with Matlab, and since I'm used to Vim's interface, I try to stay out of Matlab's editor as much as possible. What's troubling me is that every time I start a .m file, it brings up the interface.
我刚刚开始用 Matlab 做一些实验,因为我已经习惯了 Vim 的界面,所以我尽量远离 Matlab 的编辑器。令我烦恼的是,每次启动 .m 文件时,它都会显示界面。
Is there a way to start test.m from a cmd line, and let it give output out on a cmd, as it would normally do in Matlab's environment. Something like a "Matlab shell" (like Python's, only Matlab's)?
有没有办法从 cmd 行启动 test.m,并让它在 cmd 上输出,就像在 Matlab 环境中通常所做的那样。类似于“Matlab shell”(如 Python 的,只有 Matlab 的)?
回答by Dima
To answer your question, start matlab like this:
要回答您的问题,请像这样启动 matlab:
matalb -nodesktop -nosplash
matalb -nodesktop -nosplash
This does work on both linux and windows. On linux, you type this at the command prompt, and matlab will run in that same command window in text mode. So you would get the "matlab shell" you wanted. On windows, cd into the directory where matlab is installed, and type the same command. It will open a stripped-down matlab command line window, without all the bells and whistles of the matlab desktop.
这在 linux 和 windows 上都有效。在 linux 上,您在命令提示符下键入此命令,matlab 将以文本模式在同一个命令窗口中运行。所以你会得到你想要的“matlab shell”。在 Windows 上,cd 进入安装 matlab 的目录,然后键入相同的命令。它将打开一个精简的 matlab 命令行窗口,没有 matlab 桌面的所有花里胡哨。
Now in my personal opinion, the matlab editor with its integrated debugger is your friend. It also has emacs key bindings, if that helps. It is also easier to execute commands and look at the results in matlab desktop then when matlab is run in text mode. The only time you really want to use the text mode is if your matlab code takes a long time to run, and you are only interested in the final result. Or if you are running multiple instances of matlab. The text mode takes much less memory, and on linux you can easily start a run from the command line and put it into background.
现在在我个人看来,带有集成调试器的 matlab 编辑器是您的朋友。如果有帮助,它还具有 emacs 键绑定。与在文本模式下运行 matlab 相比,在 matlab 桌面中执行命令和查看结果也更容易。您真正想要使用文本模式的唯一时间是您的 matlab 代码需要很长时间才能运行,并且您只对最终结果感兴趣。或者,如果您正在运行多个 matlab 实例。文本模式占用的内存要少得多,在 linux 上,您可以轻松地从命令行启动运行并将其置于后台。
In fact, check the command line arguments for matlab. You can do other interesting things, like have matlab execute a single function and exit, a la perl, or redirect a script into matlab like this: matlab < script.m
事实上,检查 matlab 的命令行参数。你可以做其他有趣的事情,比如让 matlab 执行一个函数并退出,a la perl,或者像这样将脚本重定向到 matlab:matlab < script.m
回答by Ofek Shilon
Are you really willing to do dev work with no m-file debugger? Seems to me that would limit you to practically trivial programs. After a very brief learning curve, I think you'd find the Matlab integrated debugger to be fantastic (and I'm a VS person).
您真的愿意在没有 m 文件调试器的情况下进行开发工作吗?在我看来,这会将您限制在实际琐碎的程序中。经过一段非常简短的学习曲线后,我认为您会发现 Matlab 集成调试器非常棒(而且我是 VS 人)。
If you insist on doing so, your best option is to compile your m-files to be runnable stand alone. That would require access to the (not cheap) matlab compiler.
如果您坚持这样做,最好的选择是编译您的 m 文件以使其可独立运行。这将需要访问(不便宜的)matlab 编译器。
Note that there is a significant difference between the compiler distributed with matlab versions up to 6.5, and those distributed with matlab 7+ (don't know the compiler version numbers). In 6.5, the compiler generated c-code, that could be than edited and compiled separately. From 7 onwards, the compiler did no compiling, converting, or any code generation for that matter: running a 'compiled' program today practically runs it on a virtual Matlab machine called the MCR- which encompasses almost all matlab functionality. It is a massive one - MCR installer (installer!) weighted 130M last time I checked.
Some debate on this can still be found on newsgroups, but that's not important now. In fact, the MCR approach seems closer to what you seek.
请注意,使用高达 6.5 的 matlab 版本分发的编译器与使用 matlab 7+(不知道编译器版本号)分发的编译器之间存在显着差异。在 6.5 中,编译器生成了可以单独编辑和编译的 c 代码。从 7 开始,编译器不再为此进行编译、转换或任何代码生成:今天运行“已编译”程序实际上是在称为MCR的虚拟 Matlab 机器上运行它——它包含几乎所有的 matlab 功能。这是一个巨大的 - MCR 安装程序(安装程序!)我上次检查时的权重为 130M。
仍然可以在新闻组上找到关于此的一些辩论,但这现在并不重要。事实上,MCR 方法似乎更接近您所寻求的。
And btw, for me matlab -nosplash -nodesktop
works perfectly on windows - it launches matlab as a console, but that would deprive you both of a text editor anda debugger...
顺便说一句,对我来说,matlab -nosplash -nodesktop
在 Windows 上工作得很好——它启动 matlab 作为控制台,但这会剥夺你的文本编辑器和调试器......
回答by Hannes Ovrén
What I would do is:
我会做的是:
- Start MATLAB
- Do notopen the .m file within matlab
- Open the file in your editor of choice
- Run the function from within MATLAB as usual
- 启动 MATLAB
- 不要在 matlab 中打开 .m 文件
- 在您选择的编辑器中打开文件
- 像往常一样从 MATLAB 中运行该函数
I can't imagine any reason why this wouldn't work as MATLAB should not care what was used to edit the file.
我无法想象为什么这不起作用,因为 MATLAB 不应该关心用于编辑文件的内容。
This won't give you a "shell", but the whole GUI, but I can't think of any reason why you would not want to have that, if it is available.
这不会给你一个“shell”,而是整个 GUI,但我想不出任何你不想拥有它的理由,如果它可用的话。
回答by Mr Fooz
On Linux environments, Matlab can be started in text mode
在 Linux 环境下,可以在文本模式下启动 Matlab
matlab -nosplash -nodesktop
but this doesn't work on Windows.which starts it in the current shell. On Windows, this opens a new text-only window. I know of no way to get it to run inside the current console on Windows.
但这在 Windows 上不起作用。它在当前 shell 中启动它。在 Windows 上,这会打开一个新的纯文本窗口。我知道没有办法让它在 Windows 上的当前控制台内运行。
Perhaps there's some way you can attach to it running it in http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/matlabwindows.shtml&http://www.google.com/search?rlz=1C1GGLS_enUS302US311&sourceid=chrome&ie=UTF-8&q=matlab+command+line+windows'>automation server mode.
也许有一些方法可以附加到它在 http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/matlabwindows.shtml&http:/ /www.google.com/search?rlz=1C1GGLS_enUS302US311&sourceid=chrome&ie=UTF-8&q=matlab+command+line+windows'>自动化服务器模式。
Another option if you're really desperate could be to make a virtual machine and install linux in it. Then I imagine there are ways to configure vim to work nicely with Matlab (I'm an emacs person these days and there are solutions for emacs).
如果您真的很绝望,另一种选择可能是制作一个虚拟机并在其中安装 linux。然后我想有一些方法可以将 vim 配置为与 Matlab 很好地工作(这些天我是一个 emacs 人,并且有针对 emacs 的解决方案)。
回答by Mr Fooz
I had the same problem as Kigurai. I needed to drive Matlab with Python so I found this solution:
我和 Kigurai 遇到了同样的问题。我需要用 Python 驱动 Matlab,所以我找到了这个解决方案:
In Python:
在 Python 中:
import os
os.chdir('W:\monréperttheitroade')
os.spawnl(os.P_NOWAIT, 'monscript.bat')
In monscript.bat:
在 monscript.bat 中:
matlab.exe -r interp_3D -nodesktop –nosplash
回答by mlt
There are cases when indeed not much debugging is needed and state of the Matlab shall be preserved between invocations. One (the only?) example would be Emacs org-mode. it can be used to write text interleaved with code according to literate programming etc. While it is possible to use comments in Matlab and publish codebe it HTML or LaTeX, it does however require to leave the comfort of Emacs.
在某些情况下,确实不需要太多调试,并且在调用之间应保留 Matlab 的状态。一个(唯一的?)示例是 Emacs org-mode。它可用于根据文学编程等编写与代码交错的文本。虽然可以在 Matlab 中使用注释并发布HTML 或 LaTeX代码,但它确实需要离开 Emacs 的舒适性。
There is a standalone program availablethat uses Matlab engine to evaluate commands received on stdin, and dump the result. This particular version, however, lacks support for multiline commands like if/else/end or for/end. This is a limitation of engEvalStringthat expects everything at once. There is an ugly workaround availablethat makes it usableenough for org-mode.
有一个独立程序可用,它使用 Matlab 引擎来评估在 stdin 上接收到的命令,并转储结果。但是,此特定版本不支持多行命令,例如 if/else/end 或 for/end。这是engEvalString 的一个限制,它要求一次性完成所有操作。有一个可用的丑陋的解决方法,使得它可用于组织模式不够。
#+begin_src matlab :session *MATLAB* :exports none :cache no :results value
if 3>1
'wow!!!'
end
#+end_src
#+RESULTS:
: wow!!!