Run MATLAB in command line allowing display of plots - matlab

To run MATLAB on Linux in the command line I use the following:
matlab -nodisplay
But I guess this does not allow windows of plots to open either, because the following command has no output:
plot(X,Y)
How to allow only graphs and plots to display when running MATLAB from the command line?

Under Linux, to run MATLAB in a terminal window use the -nodesktop option. It causes MATLAB to start without the GUI, with all text input and output to happen through the terminal window. But it does not disable the JVM software altogether and so allows interactive figure windows to be displayed.
The -nojvm option disables the JVM software, disallowing all Java-based components of MATLAB, including figure windows. The -nodisplay option disables al graphical display output, but doesn't disable the JVM.
For more details, see the documentation.

Related

How to Set up Matlab's userpath in Terminal?

I want to set Matlab's userpath etc the following in Terminal, instead of doing it in GUI Matlab session.
userpath('/home/masi/Documents/bin/matlab/')
This thread is continua 2 of the thread How do I specify the MATLAB editor keybindings programmatically
about startup.m where I can set some other things.
I cannot find about it in Documentation so it must be in the undocumented part of Matlab because I know this feature can be done.
My proposal after Suever's answer
Run just once after the installation
echo "export MATLAB_USE_USERWORK=1" >> $HOME/.bashrc
matlab -nodesktop -nosplash -r \
"userpath('/home/masi/Documents/bin/matlab/'); exit;"
Problem with userpath and addpath
See test codes here. Some other configurations have to be applied too.
Matlab: 2016a
System: Linux Ubuntu 16.04
On Linux, the startup.m file should be located within the folder in which you were when you launched MATLAB from the command line.
On Linux® platforms, the default startup folder is the folder from which you started MATLAB.
If you want to use userpath as the startup folder instead of the current directory, you can specify that you'd like to use the userpath via the environment variable MATLAB_USE_USERWORK=1. This will by default point it at $HOME/Documents/MATLAB (or an alternate location if that was set within MATLAB).
To specify the userpath as the startup folder, set the value of the environment variable MATLAB_USE_USERWORK to 1 before startup. By default, userpath is userhome/Documents/MATLAB, and MATLAB automatically adds the userpath folder to the top of the search path upon startup. To specify a different folder for userpath, and for other options, use the MATLAB userpath function.
More info in the documentation
As a side note, if you need to run a MATLAB command from the terminal, it is possible to run MATLAB without the UI and have it execute the necessary command.
matlab -nodesktop -nosplash -r 'commands_here; exit;'

MATLAB still opens GUI after -nodesktop and -nosplash options

I want to open Matlab without the GUI, so pretty much just running it from the Linux terminal. For some reason adding the -nodesktop and -nosplash flags aren't working. Maybe there must be some sort of default settings, that are overwriting these flags? Is there any way to check this? Maybe I'm missing an extra flag?
$ matlab -nodesktop -nosplash
Other Details: Matlab 2012b, ran on Ubuntu 12.04.
Running:
$ matlab -nodesktop -nosplash -nojvm -nodisplay
doesn't work either.
You could try this as a workaround, it worked for me in a simple test (though I'm not running Ubuntu 12.04, so YMMV):
Before you call matlab, set the DISPLAY variable to a non-valid value. For instance:
export DISPLAY=:10.0
matlab
For me, this produces a terminal MATLAB session without a display or splash, even without the command-line options.
Although you seem to have found a workaround, you may have luck with the following command line options:
matlab -noawt -noFigureWindows ...

auto-completion in MATLAB with nodesktop option

I'm using MATLAB R2012b on a win7 computer.
When I launch MATLAB from cmd using matlab -nodesktop, the tab is disabled for auto-completion in command line window. So I have to type the full name of a file, a path or a function.
When I open GUI and set as this link says, (http://www.mathworks.com/company/newsletters/articles/avoiding-repetitive-typing-with-tab-completion.html) auto-completion works fine in GUI. But it doesn't work when -nodesktop option is used.
I used to use R2014b on a Ubuntu machine with -nodesktop option, the auto-completion function works fine.
Is there any way to enable auto-completion in cmd when -nodesktop is chosen.

view commandline with compile matlab exe

I have a matlab gui which works in matlab but if I compile it to a gui, the application
does not respond on buttons and somehow does not work.
Now I would like to see all error messages, but I can not because there is no commandline anymore.
Can I switch on a commandline ouput window for matlab executables?
One can simply run he exe from a dos shell. Alle comand line output will be available in the dos shell.

Several MATLAB command windows possible?

Is it possible to have several command windows (consoles) in matlab?
Yes, you can start multiple sessions of MATLAB in different terminals or windows. Remember that you can use the command matlab -nodesktop to have a MATLAB session without the GUI, it's very useful to save space and memory.
Within a single Matlab session, no. But you can run several sessions of Matlab in parallel on the same machine using a single license.
I think you can start up to four individual sessions of MATLAB on a machine. But the behavior of the MATLAB startup program seems to be different depending on the OS and MATLAB versions.
On Windows, you may be able to start another session by just clicking the icon on the Programs Menu.
On Mac OSX, depending on the MATLAB version that you use, you may have to do 'Show Package Content' (right mouse click over the icon in the Applications folder) and directly double-click the executable file called 'matlab' under the /bin directory (or over its alias) to start another session.
On Linux, you can just type 'matlab' on the Console and start another session.