Starting Matlab textually - user-interface

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.

Related

Read Performance counter in Mac from terminal

I would like to know how to get
performance monitoring counter measurements on a Mac. With Linux, we
can use the "perf stat" command to get measurements. With a Mac it's
harder. Specifically, I would like to know how I can get the number of
branch mispredictions and the number of branches executed for a
program running from the command line, preferably without recompiling
the program. I have done some Googling but what I need is a solution;
if you can show me how you brought up a terminal, typed in some
command (maybe using some tool you downloaded), and got the number of
mispredictions for, say /bin/ls, that would be great.
Official macOS tool to work with profiling, both based on software events and on hardware events (performance counters), is Instruments tool - https://help.apple.com/instruments/mac/current/. It seems to be part of XCode development tools.
This tool have some limited variants to collect profiles from command-line mode, check https://help.apple.com/instruments/mac/current/#/devb14ffaa5
https://help.apple.com/instruments/mac/current/#/devba105ecc
Launch Instruments from the command line
You can use the open command to launch any app in OS X via Terminal,
including Instruments.
Launch Terminal (in /Applications/Utilities/).
Run the following command:
open /Applications/Xcode.app/Contents/Applications/Instruments.app
The Instruments app launches.
Note: You can also use either of two command-line utilities to profile
an app without actually displaying the Instruments user interface.
instruments — This utility profiles an app using a specified template. The results can be saved to a file and then manually opened
in the main Instruments app for viewing and analysis. To learn more,
go to Profile with the instruments command-line tool.
To get IPC or branches, use GUI to create profile with usage of counters usage (1 or 2) and save it as template, and then use CLI tool instruments to collect trace data. Trace file can be viewed with Instruments GUI; there was incomplete attempt to decode that files.
The page https://medium.com/#pavelkucera/counting-branch-mispredictions-on-macos-7397ae8c5b51 also lists another variant to work with hardware counters on macOS, the https://github.com/opcm/pcm project:
You first have to build the tool, but then it is easy to use:
run pmu-query.py
enter “BR_INST_RETIRED.NOT_TAKEN”, the result should be similar to: cpu/umask=0x10,event=0xC4,name=BR_INST_RETIRED.NOT_TAKEN/
run ./pcm-core.x -e event where “event” stands for the result from the previous step
This gives you continuous results for all the running processes. Find
info on how to profile a single process in ./pmc-core.x --help
The good news is that results are easily readable as they can be
output as csv file. The bad news is that profiling a single process
still includes activity from other processes.

How do I open a program in a Win32 Console without cmd.exe?

I have little previous experience with Windows (for programming, anyway), but recognizing that Windows has an enormous market share, I am trying to support it in my programs (even though they are just for fun, I like to pretend they're big projects). I have written a tiny shell with minimal (and when I say minimal, I mean minimal) features.
I am trying to port it to Windows and would like to use it independently from cmd.exe in a Win32 Console window (meaning the shell part of cmd.exe isn't running at all, but the window used for it shows). I have already done most of the other porting stuff such as build system (CMake) and changing appropriate Unix syscalls to Windows ones in a #define. I have done a little research and found little on this topic, however. I know it is possible because I've seen it done with Bash. Visual Studio also used to do it when I ran a program in its GUI.
Reference article I got some of this info from: https://en.wikipedia.org/wiki/Win32_console
Note: What I mean is when you click on it and it opens it without running cmd in its own little console window. Or when you type it into cmd it opens in a separate window that isn't running cmd. I am assuming cmd.exe and the console window it runs in are two separate things, but if I am wrong, please let me know. :)
This question is inspired by https://askubuntu.com/questions/111144/are-terminal-and-shell-the-same and a similar question where I got that Wikipedia link. Someone said that the console window and the shell were separate. I was writing my own shell so I started to wonder how to make mine independent of the default one.
The Win32 Console and cmd.exe are two different things. Windows automatically opens a console window when a program that needs one is started. It decides whether do to so by switches hard-wired into the executable. This window will be running said program. If the program that started the process is running in a console window, the two programs will share that console window.
As Noodles said, it really is that simple. You just start it. Double-clicking on it will do it. The CreateProcess() function with CREATE_NEW_CONSOLE passed to it will do it. Running the program from cmd.exe with
start <command>
will do it.
There is also a family of functions in the Windows API, called FreeConsole() and AllocConsole() that will free a program from its current console and create a new console for it, respectively.
Reference link (given by Noodles): https://msdn.microsoft.com/en-us/library/windows/desktop/ms682010(v=vs.85).aspx

How to stop MATLAB from opening a new window using Cygwin?

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.

user-friendly application entry points in MATLAB or SciLab

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))'

Matlab on cmd (winxp)

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!!!

Resources