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.
Related
I'm trying to find a CMD code to run a MATLAB file but when MATLAB is already running (I don't want to open MATLAB again in different window).
I'm using this code:
matlab -nosplash -r run('C:\xampp\htdocs\RCE\FYP_expirement\SpeedControl\exp1_start.m');
But every time this code is executed (from a batch file), it opens MATLAB again in a separate window.
I use a DOS batch script to call the matlab Command Window (matlab -nodesktop -nosplash -noFigureWindows -r "myscript"), and the script relies on some functions in different folders, which are in my path.
When I run this, the matlab Command Window which is created cannot find one of these functions, saying 'undefined function or variable'.
This function is definitely in my path in the full Desktop version of matlab, but the path loaded in the Command Window version does not have that folder in it.
Calling which pathdef gives the same file in both versions, and they both have the same contents, but calling p=path; gives different paths, with the Command Window version only having psychtoolbox folders and the '\Documents\MATLAB' folders, not the folder this function is in.
Do you know how to get the Command Window to use the same path as the Desktop Window?
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;'
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.
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.