Several MATLAB command windows possible? - matlab

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.

Related

how do I mimic the terminal path when making a system call in MATLAB on a mac

I'm trying to automate mac terminal calls in MATLAB. In my specific use case I used brew to install cmake but in MATLAB cmake isn't recognized [~,result] = system('cmake ..'); returns zsh:1: command not found: cmake
Using the following I am pretty sure I could update the path so that cmake is recognized.
(Mac,Matlab,bash) Changing the PATH of bash in Matlab for system commands
However, I was wondering if there was a generic way of mimicking the path that the terminal is seeing.
In particular when I run env in the terminal and in MATLAB using [~,result] = system('env'); the path variables are different and I'm wondering why that is and how to ensure they align.
When you start MATLAB from its icon on macOS, you never ran the login shell startup files, so most of your configuration is not loaded. That is, anything configured in ~/.zprofile, ~/.zshrc, etc. is not seen by MATLAB. Unlike other Unixes, macOS doesn’t start a login shell when you log on. See here for the differences between a login shell and a non-login shell.
One way around this is to launch MATLAB from a terminal window. Another way is to manually load the zsh configuration before running your shell command.
A cleaner solution is to avoid ~/.zprofile (loaded for login shells) and ~/.zshrc (loaded for interactive shells), and instead put your configuration in ~/.zshenv (loaded for all shells, including the one started by MATLAB for system() or !).
In particular, Homebrew adds a line
eval "$(/opt/homebrew/bin/brew shellenv)"
to your ~/.zprofile file. Moving this line to ~/.zshenv and restarting MATLAB should add the Homebrew configuration to shells started from within MATLAB.

VS Code Integrated terminal does not execute commands from extensions

Ideally, the integrated VS Code terminal, depending on the context, the type of the folder and the extension, executes some commands. For example, when opening a folder containing a Python virtual environment in VS code, the environment is recognized and activated (by the python extension) by default when opening a new integrated terminal instance (situation 1). This is done by running some command similar to source /path/to/venv/bin/activate.
Or, when using the ROS extension to debug nodes, selecting "Start Debugging (F5)" uses the launch.json file to start some nodes and finally starts debugging the desired code. To do so also, there is some command that is executed (also by he ROS extension, I assume) in the integrated terminal (situation 2) to start the debugging process. In case of debugging ROS nodes, the command usually looks something like /usr/bin/env /bin/sh /tmp/someFileName.
But, unfortunately, both of the above mentioned situations fail. I believe this happens because while the extension tries to run these two commands within their respective integrated terminals, the commands do not actually get executed in either situation. Instead, these commands are printed on the top of the terminal, but the state of the terminal is unchanged (as opposed to when the commands would have been executed, in which case depending on the commands some actions are performed). Here are two images to show what I mean. Top, situation 1 and bottom, situation 2.
The fact that these two commands are printed on top of the terminal as soon as the a new terminal instance is opened tells me that the extension tries to execute them, but they do not work for some unknown reasons.
Just to be clear, both of them are run in a seperate VC Code window, they have nothing to do with each other. When I manually run both the commands in their respective terminals I do get the desired results.
Now, I am unsure exactly how to name this issue. But I think this is surely an issue with the integrated terminal, and not a problem of the extensions. I am not sure how one could reproduce this problem.
I did a clean reinstall of VS code by deleting %APPDATA%\Code and %USERPROFILE%\.vscode. Because I am using this on WSL, there is only ~/.vscode-server on the ubuntu side. I manually uninstalled all extensions on WSL but did not delete this folder, in fear of breaking something. The problem still persisted. I have also created an issue on the VS Code GitHub page with nearly the same information.
I am unsure if this is a bug or is there something wrong with my settings. Does anyone know how I could fix this? For smaller use-cases I can still manually enter the command in the terminal. But I am trying to debug a ROS application with nearly 10 different terminals opening up and I cannot be manually entering the command each time to restart the process.
Please let me know if you need any more information. Many thanks in advance.
Edit: both edits to frame the question properly.
Although not related to WSL, I dug a little deeper today as to why in my case the extension commands were not being executed or were being chopped.
I'm an iTerm2 user. iTerm2 has something called Shell Integrations, which allow iTerm to behave differently under certain circumstances, for example, adding markers to each prompt or coloring output with certain text (e.g. WARNING or ERROR)
From time to time, I also use the VSCode Integrated Terminal, which recently added support for reporting whether the previous command errored out with an indicator on the gutter of the Integrated Terminal panel using the exit code.
iTerm can do something similar but the shell integrations mess up completely the VSCode functionality and therefore I changed my .bashrc file to detect if the terminal emulator was iTerm2 or not (which can be done with the it2check utility of iTerm2) so that it only sourced the shell integrations if I was using iTerm2.
The problem is that it2check "eats" some STDIN bytes using dd, specifically, until it finds an n so that it can obtain the name of the emulator. This of course chops the commands on the STDIN until the first n and makes VSCode Extension Terminal commands unusable
The workaround I came up with is to use the value of "$TERM_PROGRAM" as means to distinguish between the different programs. The only caveat is that the value won't be passed if you're inside of a tmux session or similar, but I can live with that.
In your case, I'd check for any process that is either not passing the STDIN to the WSL process or any dot files or shell profile scripts eating up the STDIN they receive.
I suspect that the real problem is that the local process doesn't relay the STDIN contents to the WSL and as a workaround you may try to create a VSCode Integrated Terminal profile that uses SSH to connect to the WSL host so that the STDIN is preserved

Selecting Python interpreter from WSL

I am using Windows 10 and want to set the the default VSCode interpreter for Python to be the same one used in my WSL 2 (Ubuntu), so that I'm always using "one Python".
When I click "Select Python interpreter" a prompt appears to find the interpreter path, but I'm not sure what the path would be.
I think that, in order to use the WSL python, you need to be running VSCode in a WSL remote window. You need to install the Remote WSL extension first. Then, on the lower left there is a green button that will let you start a WSL window, or it will tell you that you are already in one.
If you are in a WSL window, you should be able to select your python interpreter pretty easily. It will either automatically detect it, or you can run which python3 in an Ubuntu terminal to get the path. If you want to navigate to a file on your Windows file system from within this window, look in, e.g., /mnt/c/Users/<USER_NAME>.
Well probably late to the party but you can find Python you are using on your WSL2 with simple command:
which python3
It will show you where is the python placed.
While above answers work, there are some related things to keep in mind here (or are at least worth mentioning):
I would recommend to create a virtual environment for your project. If you do so, its very easy to find the python interpreter in the bin folder of the venv. (If you want to "find" your WSL folder in windows. Just enter explorer.exe . in your terminal - it will open a windows explorer in the current location.
If you open the python interpreter selector form within VS Code on Windows, be aware that it opens a windows that let's you select "Executables" (meaning WINDOWS wxecutables):
You will not be able to open your python interpreter located in your wsl like that, as the folder will be shown as empty.

What is AU3_Spy.exe? Where can I find it?

Whenever I try to launch the Windows Spy utility in AutoHotkey, it fails with an error "Could not launch file: U:\Software\AutoHotkey_1.1.26.00\AU3_Spy.exe"
Initially I thought that I may have had a corrupted download. However, after redownloading AHK from the official website, I could not find any file named AU3_Spy.exe in ahk.zip.
After some research, I've discovered that the portable version of AHK is missing AU3_Spy.exe, which seems to be required for Window Spy to run.
What is AU3_Spy.exe?
Why wasn't it included with AutoHotkey?
Where can I find the missing file?
Window Spy or AU3_Spy.exe is a program which can be used to retrieve information about a window for scripting.
While it isn't included with the portable version of AHK ahk.zip, you can use 7-Zip to extract AU3_Spy.exe from the AutoHotkey installer.
Download the AutoHotkey installer (https://www.autohotkey.com/download/)
Open installer file using 7-Zip and extract AU3_Spy.exe.
Place AU3_Spy.exe in your AutoHotkey folder.
While running AHK, right-click the AHK icon in the notification area and select Window Spy.
Done! You can now click any window to retrieve useful information such as window title, mouse position, and controls.
TL;DR: All older answers are now obsolete and don't reflect current situation.
The last release that includes standalone Windows Spy utility is 1.1.26.01.
Here is the link to 1.1.26.01 installer download.
Since v1.1.27.00, AutoHotKey_L no more includes Windows Spy utility (AU3_spy.exe) as a standalone exe; it is replaced by WindowSpy.ahk as noted in comment of another answer. Here is the relevant excerpt of release announcement:
Replaced AU3_Spy.exe with WindowSpy.ahk.
AU3_Spy.exe is still launched if WindowSpy.ahk is not found.
It now follows the focused control by default, and has a checkbox for both window and control to follow the mouse.
It no longer takes over a global hotkey (Win+A). Instead, hold Ctrl or Shift to suspend updates (release them after focusing Window Spy).
It is now possible to Alt-Tab to Window Spy on Windows 10 without the contents of the GUI changing.
As other answers have stated, use 7-Zip to extract AU3_spy.exe within the installer, then place it in any location of your favorite choice, and call it a day.
For 1.1.x users, they can actually use the new spy script to get equivalent functionality.
But not so fortunate for AutoHotKey 2.0 alpha/beta users, as the script was written in 1.x language, which is incompatible with 2.0. For them, getting the standalone exe is the only option. (There exists other replacement utilities, such as Spy++ from Visual Studio, but not as convenient.)
In latest AutoHotkey installer (v1.1, v2.0...), only Full-installer includes that, and after installation you can find it:
C:\Program Files\AutoHotkey\WindowSpy.exe
Try running the standalone installer:
https://autohotkey.com/download/ahk-install.exe
Then look for your file here:
\Program Files (x86)\AutoHotkey\AU3_Spy.exe

Open a GUI directly from desktop (Shortcut) in MATLAB environment

I want open a GUI directly from desktop without opening MATLAB and run it from it. When I right click on the main MATLAB code file and select Run in windows environment, MATLAB starts and after that my GUI automatically runs but I want have this with double clicking on an Icon (shortcut) o desktop. How can I do this? I don't want compile my app.
My GUI contains training neural network so I can't compile it.
What you actually need is a way to run .m files via the command line - an action which isn't specific to GUIs. A command line operation is something you can bind to a shortcut on your desktop or execute using a batch file.
The solution you're looking for is a combination of MATLAB-specific syntax and a straightforward batch file creation procedure:
Open a text editor.
Write this inside:
"C:\<path to your MATLAB folder>\matlab.exe" -nodisplay -nosplash -nodesktop -r "cd('C:\<path to your where the .m file is>\'); run('C:\<path to where the .m file is>\mfile.m');"
Save the file as .bat (in windows) and run.