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.
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)?
To answer your question, start matlab like this:
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.
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.
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
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).
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.
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.
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 and a debugger...
What I would do is:
Start MATLAB
Do not open the .m file within matlab
Open the file in your editor of choice
Run the function from within MATLAB as usual
I can't imagine any reason why this wouldn't work as MATLAB should not care what was used to edit the file.
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.
On Linux environments, Matlab can be started in text mode
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.
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.
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).
I had the same problem as Kigurai. I needed to drive Matlab with Python so I found this solution:
In Python:
import os
os.chdir('W:\\monrépertoire')
os.spawnl(os.P_NOWAIT, 'monscript.bat')
In monscript.bat:
matlab.exe -r interp_3D -nodesktop –nosplash
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 code be it HTML or LaTeX, it does however require to leave the comfort of Emacs.
There is a standalone program available that 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 engEvalString that expects everything at once. There is an ugly workaround available that makes it usable enough for org-mode.
#+begin_src matlab :session *MATLAB* :exports none :cache no :results value
if 3>1
'wow!!!'
end
#+end_src
#+RESULTS:
: wow!!!
Related
In the past, I have used MATLAB sparingly from Linux machines at work, and I far and away preferred using the '-nodesktop' option. On all Unix-like machines I've worked on this option allows me to control STDIN and STOUT with relative ease, but on Windows(using Cygwin) this option spawns a new window and control is returned to the calling shell!
Basically, I would like to know if there is any way that I can force MATLAB to behave as it would on a Unix-like machine?
Thanks!
Short answer: You can not.
A longer answer can be found on their website.
-nodesktop behaves differently depending if you are on Windows vs
Linux or Mac. On Windows we provide a boring Command-Window only
interface that lacks the “bells and whistles” of the regular Command
Window or the full Desktop.
So you can use -nodesktop, but it pops up that annoying command line only window.
In Linux terminal, I was wondering what differences are between the following four options for Matlab command?
matlab -nojvm -nodesktop -nodisplay -nosplash
I searched on the internet, and the four options seem to be
redundant, especially used together?
Can they be ordered from more graphical to less graphical, or less
textural to more textural? For example, can they be ordered in some
way from weak to strong as: -nodesktop < -nojvm <-nodisplay?
How do you know the JVM is started in -nodisplay, and not in -nojvm?
In other words, what functionality that is provided by JVM still
work under -nodisplay?
Thanks and regards!
This is all explained in the MATLAB documentation here: http://www.mathworks.nl/help/techdoc/ref/matlabunix.html.
-nodisplay: Start the Sun Microsystems JVM software, but do not start the MATLAB desktop. Do not display any X commands, and ignore the DISPLAY environment variable,
-nodesktop: Start MATLAB without bringing up the MATLAB desktop. The JVM software is started. Use the current window in the operating system to enter commands. Use this option to run without an X-window, for example, in VT100 mode, or in batch processing mode. Note that if you pipe to MATLAB using the > constructor, the nodesktop option is used automatically. With nodesktop, MATLAB does not save statements to the Command History. With nodesktop, you can still use most development environment tools by starting them via a function. For example, use preferences to open the Preferences dialog box and doc to open the Help browser. Do not use nodesktop to provide a Command Window-only interface; instead, select Desktop > Desktop Layout > Command Window Only.
-nojvm: Start MATLAB without the JVM software. Use the current window to enter commands. The MATLAB desktop does not open. Any tools that require Java software, such as the desktop tools, cannot be used. Handle Graphics and related functionality are not supported; MATLAB produces a warning when you use them.
-nosplash: starts MATLAB but does not display the splash screen during startup.
I have a Python program that is mostly complete, and there is one thing that I'd like to change, which may or may not be possible.
This program uses PyQT to display a GUI and I have it pretty much pinned up so I was wondering if I can make Python not open up a termianl when I open the program.
I am using Windows XP right now, but the machines it will run on will be Windows 7. I generally work with Linux, so I'm not terribly familiar with Windows.
If the terminal has to be there, it's no big deal, but I feel like it's extraneous at this point.
Thanks!
Use the python extension .pyw.
E.g program.pyw
This causes your program to be run with pythonw.exe instead of python.exe which suppresses the terminal.
I have an application I would like to write in either MATLAB or SciLab. This question is not about the application itself, but about entry points.
I would like a way for users to click on an icon or shortcut or whatever, and execute the following steps:
If MATLAB or SciLab is not running, launch it and wait until the launch is complete. If it is running already, proceed to step 2.
Run my application (MATLAB or SciLab script)
Any suggestions?
If the only way to do this is from within MATLAB/SciLab (vs. at the command-line) then I'll live with that, but I need to know how to do it.
Put yourself in a user's shoes: You know nothing about MATLAB or SciLab, and a coworker has given you this application that runs under MATLAB/SciLab to use.
What is the easiest way to get that user to be able to use the application, without having to teach them MATLAB commands or setting the MATLAB path or anything like that. (Ditto for SciLab.)
You can call Matlab from the command line. So you could wrap the command line call in a shortcut and all the user would have to do is double click it. I would take a look here and see if these use-cases will help, although I suspect they will.
You can do things like:
matlab -nosplash -nodesktop -r 'plot(0:.1:pi,sin(0:.1:pi))'
I have been running drush scripts (for Drupal) with Cygwin on my relatively fast windows machine, but I still have to wait about a minute for any drush command (specifically drush cache clear to execute).
I'm quite sure it has something to do with the speed of Cygwin since my fellow developers (who are running Linux) can run these scripts in about 5 seconds.
Is there a way to make Cygwin use more memory and/or CPU per terminal?
The problem you're running into is not some arbitrary limit in Cygwin that you can make go away with a settings change. It's an inherent aspect of the way Cygwin has to work to get the POSIX semantics programs built under it expect.
The POSIX fork() system call has no native equivalent on Windows, so Cygwin is forced to emulate it in a very inefficient way. Shell scripts cause a call to fork() every time they execute an external process, which happens quite a lot since the shell script languages are so impoverished relative to what we'd normally call a programming language. External programs are how shell scripts get anything of consequence done.
There are other inefficiencies in Cygwin, though if you profiled it, you'd probably find that that's the number one speed hit. In most places, the Cygwin layer between a program built using it and the underlying OS is pretty thin. The developers of Cygwin take a lot of pains to keep the layer as thin as possible while still providing correct POSIX semantics. The current uncommon thickness in the fork() call emulation is unavoidable short of Microsoft adding a native fork() type facility to their OS. Their incentives to do that aren't very good.
The solutions posted above as comments aren't bad.
Another possibility is to go through the drush script and see if there are calls to external programs you can replace with shell intrinsics or more efficient constructs. I wouldn't expect a huge speed improvement by doing that, but it has the nice property that you'll speed things up on the Linux side as well. (fork() is efficient on Linux, but starting external programs is still a big speed hit that you may not have to pay as often as you currently do.) For instance:
numlines=`grep somepattern $somefile | wc -l`
if [ $numlines -gt 0 ] ; then ...
would run faster as:
if grep -q somepattern $somefile ; then ...
The first version is arguably clearer, but it requires at least three external program invocations, and with primitive shells, four. (Do you see all of them?) The replacement requires only one external program invocation.
Also look at things that slow down Cygwin startup:
Trim down your Windows PATH (to the bare bones like %SystemRoot%\system32;%SystemRoot%)
Remove things you don't need from bashrc and bash_profile
Move things you only need in your terminal window from bashrc to bash_profile
One surprisingly large time suck in Cygwin is Bash completion. If you are using it (and you should because it's great), only source completion for the commands you need (rather than all of them which used to be the default). And, as mentioned above, source them from bash_profile, not bashrc.
You can give Cygwin a higher priority.
Write a new batch file, for example, "cygstart.bat" with the following content:
start "Cygwin" /high C:\cygwin\Cygwin.bat
The /high switch gives the shell a higher process priority.