I want to setup the keyboard keybindings as Windows Default Set and I would like to do this at startup using the startup.m because I want this setting to be set on a large number of systems.
The equivalent setting in the preferences dialog is: MATLAB > Keyboard > Shortcuts > Active Settings: Windows Default Set.
Proposal of startup.m after Suever's answer
See line 8
% TODO set startup script in $HOME/Documents/bin/matlab/startup.m in Terminal
% all commands here will be run at startup etc startup.m
% TODO set user path as relative by $HOME/Documents/bin/matlab/
%userpath('/home/masi/Documents/bin/matlab/')
% TODO How to set up userpath outside this Matlab script in Terminal?
% http://stackoverflow.com/a/38188945/54964
if ( not( com.mathworks.services.Prefs.getStringPref('CurrentKeyBindingSet') == 'Windows' ) )
com.mathworks.services.Prefs.setStringPref('CurrentKeyBindingSet', 'WindowsDefaultSet.xml')
end
% Event errors else with touchpad scroll
!synclient HorizTwoFingerScroll=0
Matlab: 2016a
System: Linux Ubuntu 16.04
If you want to do this programmatically you can do it using the undocumented functions for setting the preferences.
com.mathworks.services.Prefs.setStringPref('CurrentKeyBindingSet', 'Windows')
If you want a different keybinding, you can set the value explicitly from the preferences dialog and then call the following to retrieve the value.
com.mathworks.services.Prefs.getStringPref('CurrentKeyBindingSet')
This command should only have to be run once per MATLAB installation so placing it within the startup.m file may be overkill and would also prevent users from being able to change your default settings.
Related
I want MATLAB to run a function after I press a specific key "s" from the keyboard while I am within the MATLAB application (focused in MATLAB window). Is there a way to do that without the use of any external packages or libraries?
Thank you.
You can set custom shortcuts in Matlab by selecting:
Home > Preferences > Shortcuts
The closest option to what you want is "evaluate entire file" which runs the current script / function file open in the editor. I don't know of any ability to run a specific function using this, but you can assign the shortcut "S" as shown below.
I'm building a GUI in MATLAB and currently adding custom menus using uimenu. I'm trying to add different accelerators to different menu actions.
I've found that passing char(10) (newline) as the accelerator character in uimenu (see below) matlab adds Ctrl+ Enter as that menu's accelerator label. The problem is that it will not run the callback when I hit Ctrl+ Enter.
Any ideas why this doesn't work? Am I missing something? Is the Ctrl+ Enter for "run current section" cancelling my call? In that case, can I override it?
Example
A quick demonstrative example of how MATLAB will not accept Ctrl+ Enter
function test
close all
f=figure;
m=uimenu(f,'Label','test');
uimenu(m,'Label','a','callback',#hittest,'Accelerator','r');
uimenu(m,'Label','b','callback',#hittest,'Accelerator',char(10));
function hittest(h,~)
disp(h.Label)
end
end
As you've stated, it appears the main application has registered this accelerator and is therefore preventing your GUI from intercepting this call.
You could try to change MATLAB's keyboard shortcut in the shortcut preferences dialog. Note that this will only affect your installation of MATLAB.
If you start MATLAB in -nodesktop mode, then this will prevent the MATLAB IDE from launching the IDE and should free up the accelerator for your use.
matlab -nodesktop
Since you mention that this will be a deployed application, you could always use isdeployed to check if it is being run as a deployed application and if it's not then you could use an alternate keyboard shortcut so you don't have to continuously start MATLAB without an IDE
if ~isdeployed
% Use some other keyboard shortcut for testing
set(hmenu, 'Accelerator', <some other key for testing>)
else
% Use the enter key on deployed applications
set(hmenu, 'Accelerator', char(10))
end
You could also make it so that any time your app is deployed or matlab is being run with -nodesktop it would use the enter key:
if usejava('desktop')
% Use some other keyboard shortcut for testing
set(hmenu, 'Accelerator', <some other key for testing>)
else
% Use the enter key on deployed applications
set(hmenu, 'Accelerator', char(10))
end
I am using matlab R2012b, with the eeglab plugin. This is a plugin with a GUI, while this is very helpful I want to be able to see what functions the plugin is running when I use the GUI is this possible?
If you enter the command EEG.history into the command window after your session with EEGLAB it will print out a list of the commands called for the session.
example ...
EEG.history
ans =
EEG = pop_fileio('D:\work\Matlab libraries\training_course_materials\Eeglab_data.set');
EEG.setname='temp_file';
EEG = eeg_checkset( EEG );
If you then select a function of interest, e.g. highlight pop_fileio above and then right click you can select 'Open selection' option from the popup menu and the file pop_fileio.m' will open in a new tab in the MATLAB editor for you to look at it.
It's worth noting that when you run EEGLAB as a GUI that a lot of subsequent function calls are made with default parameter setting however if you call them directly from your own code you can then change these default settings.
You can follow the execution of a program using debugger. It is very easy using matlab's editor. Alternatively you can use profiler to see what was exectured and how many times.
When you select an option on the GUI, a new form/window will open. The name of the fucntion will be displayed at the top of this new window. Locate where you have stored EEG lab and find the function pertaining to the name and you can view the details in your editor window.
I'm running Matlab 2013a, under Linux, using Xmonad (using the XMonad.Config.Xfce package).
This problem occurs whether the command window is docked or not.
The command window prompt does not get the keyboard focus unless the pointer is located
over the command window.
Is there a way to get the Matlab command window to have focus behaviour just like other normal windows, like a terminal?
Most important: I'd like to have the keyboard focus follow the window focus,
and not require any special positioning of the pointer, so that I can just "Alt-Tab" around my windows and have the command window get the keyboard focus. All of the resources I've found so far relate to programmatic control of focus; I'm just trying to improve my user experience in an interactive session.
To get keyboard focus on the Command Window, include the following in your xmonad.hs
import XMonad.Hooks.SetWMName
import XMonad.Hooks.ManageHelpers
and configure your ManageHook as follows
myManageHook = composeAll . concat $
[ [appName =? a --> doCenterFloat | a <- myFloatAS ]
, (your other hooks)
] where
myFloatAS = ["MATLAB"]
Finally, include setWMName "LG3D" in your startupHook. See here for a full xmonad.hs configuration which uses this (this is where I found the solution). If you have other Java apps that don't get focus as they should you can add them to the myFloatAS list.
It's a problem in the built-in java.
If i run:
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre
matlab -desktop
Matlab works as expected.
I ran into this problem, running MATLAB2014a. I set up setWMName "LG3D" but still i couldn't get focus on my window. I had to click on the focused window to get the cursor, and sometimes the situation was even worse and I had to click on random places till i get my cursor back. This wouldn't happen on MATLAB2010. What worked for me was to use the native version of java as describe above.
In the end, i used the following bash script to start matlab8:
#!/bin/bash
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk-amd64/jre/
/usr/local/bin/matlab8 -desktop -nosplash
Isn't that nicely recursive?
I've got a portable command prompt on my external drive, and it has a nice .bat file to configure some initial settings, but I'd like more!
Here's what I know how to set from .bat:
Colors = (color XY) where x and y are hex digits for the predefined colors
Prompt = (prompt $p$g) sets the prompt to "C:\etc\etc >" the default prompt
Title = (title "text") sets the window title to "text"
Screen Size = (mode con: cols=XX lines=YY) sets the columns and lines size of the window
Path = (SET PATH=%~d0\bin;%PATH%) sets up local path to my tools and appends the computer's path
So that's all great. But there are a few settings I can't seem to set from the bat. Like, how would I set these up wihtout using the Properties dialogue:
Buffer = not screen size, but the buffer
Options like quick edit mode and autocomplete
Popup colors
Font. And can you use a font on the portable drive, or must it be installed to work?
Command history options
Regarding setting the buffer size:
Using mode con: cols=XX lines=YY sets not only the window (screen) size, but the buffer size too.
If you specify a size allowed by your system, based on available screen size, you'll see that both window and buffer dimension are set to the same value; .e.g:
mode con: cols=100 lines=30
results in the following (values are the same):
window size: Width=160, Height=78
buffer size: Width=160, Height=78
By contrast, if you specify values that are too large based on the available screen size, you'll see that the window size changes to its maximum, but the buffer size is changed to the values as specified.
mode con: cols=1600 lines=900
With a screen resolution of 1280x1024, you'll get:
window size: Width=160, Height=78
buffer size: Width=1600, Height=900
You can set these values through a shortcut (.INK file).
I have a shortcut on my desktop with this as the target:
%windir%\system32\cmd.exe /K %userprofile%\STARTUP.CMD
The /K switch tells CMD.exe to run the batch file (which sets some variables, the prompt, etc.) and then stay open.
If you right-click on the shortcut and view its properties, you can set the window and buffer size, popup colors, starting position (x,y axis), etc. The settings will be saved in the shortcut itself and will be applied every time you open CMD.exe using that shortcut.
Regarding auto-completion:
File and Directory name completion is
NOT enabled by default. You can
enable or disable file name completion
for a particular invocation of CMD.EXE
with the /F:ON or /F:OFF switch. You
can enable or disable completion for
all invocations of CMD.EXE on a
machine and/or user logon session by
setting either or both of the
following REG_DWORD values in the
registry using REGEDT32.EXE:
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\CompletionChar
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\PathCompletionChar
and/or
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\CompletionChar
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\PathCompletionChar
with the hex value of a control
character to use for a particular
function (e.g. 0x4 is Ctrl-D and 0x6
is Ctrl-F). The user specific
settings take precedence over the
machine settings. The command line
switches take precedence over the
registry settings.
If completion is enabled with the
/F:ON switch, the two control
characters used are Ctrl-D for
directory name completion and Ctrl-F
for file name completion. To disable
a particular completion character in
the registry, use the value for space
(0x20) as it is not a valid control
character.
Couldn't find any command history options in there ( cmd /? ), and it looks like the other options you asked about are set exclusively through registry settings.
For true Buffer Size adjustment use DOSKEY /LISTSIZE=size
You can't change colors within the shell anymore since Microsoft took ANSI ESC control out of the command/cmd prompts.