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.
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.
In Simulink, certain error messages provide clickable links to the origin of the error.
See, for example, the following error:
If I click one of the three links in the message, say, Parent setting, Simulink opens the code generation settings dialog and indicates the specific setting(s) using a blue border:
As a user, can I achieve the same highlighting programmatically (using a .m-script)? If so, how?
Yes, this is possible, but it requires the use of Simulink internal support functions. Their API is undocumented and may therefore be unstable. Use at your own risk.
The highlighting in the question is achieved as follows:
slprivate('modelref_highlight_configset_setting', 'rtwdemo_capi', 'RTWCAPISignals')
Here,
slprivate is a .m-function that ships with Simulink. There is no help entry for the function. Its only mention in the help is on the 'Set Simulink Preferences' help page. Its implementation is simple: it is a wrapper around feval. The implementation can be opened by executing the command >> edit slprivate from the Matlab Command window.
The function's documentation is as follows:
slprivate is a gateway for internal support functions used by Simulink.
VARARGOUT = slprivate('FUNCTION_NAME', VARARGIN)
In the usage above, the first parameter 'modelref_highlight_configset_setting', is the Simulink internal support function. In this case, it is the function that does the highlighting.
The second parameter 'rtwdemo_capi', is the name of the Simulink model whose Configuration Parameters window should be opened for highlighting.
The third parameter, 'RTWCAPISignals', is the name of the configuration option to highlight. In this case, that single option highlights two UI elements.
Names of configuration options can be found as follows:
Open the model's Configuration Parameters window (e.g. in Simulink: menu Simulation -> Model Configuration Parameters, or Ctrl + E)
Right-click on (or, rather, next to) the option
In the context menu that appears, click What's This?
In the help window that appears, scroll down to Command-Line Information. The name of the option is given in the Parameter field.
Edit:
The way I figured this out may be useful for other internal functions, so I'll leave that here as well. If the build is started from the Command Window (>> rtwbuild('rtwdemo_capi')) instead of from the GUI, warning and error messages are printed to the command window as well, including the clickable links. If one then hovers over such a link with the mouse pointer, the corresponding command is shown in the Matlab status bar (at the bottom of the main Matlab window).
I want to capture when the user holds down the control key and presses the enter key on a figure window. Note: This is the default keys for "Evaluate Current Section" in the editor.
See example code below:
function test
f = figure;
f.KeyPressFcn = #myKeyPressFcn;
end
function myKeyPressFcn ( hFig, event )
cm = hFig.CurrentModifier();
if ~isempty ( cm )
fprintf ( 'CurrentKey: %s:%s\n', cm{1}, hFig.CurrentKey );
else
fprintf ( 'CurrentKey: %s\n', hFig.CurrentKey );
end
end
To reproduce save the above in an active file in the editor and run the function - the editor needs to be open (this is important!!).
With the figure active press any key -> the selected key is written to the terminal window. However if you hold down Control and press the enter (return) key then this is not captured but instead Matlab attempts to "Evaluate Current Section" (or cell as it used to be called) in the editor (no matter that the figure has the focus). This of course throws as error...
I have contacted Matlab support and this is "expected behaviour!". I can (just about) see why it might be a good idea for demos - but for professional applications that run in Matlab I personally think this "feature" is a bug!!
Notes
When the editor is closed the control+enter is captured in the figure
In deployed applications the control+enter is captured.
If I manually change the Evaluate Current Section shortcut then control+enter is captured.
I have tried a number of things to resolve this but none have worked, for example hiding the editor or setting editor enable state to false (neither of these are acceptable solutions - I was trying to see what I could get to work on a small test case...):
function test
desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
jEditor = desktop.getGroupContainer('Editor').getTopLevelAncestor;
jEditor.setVisible(false);
jEditor.setEnable(false);
f = figure
f.KeyPressFcn = #myKeyPressFcn;
uiwait(f);
jEditor.setVisible(true);
jEditor.setEnable(true);
end
The only way I can get it to work is to close all of the editor files on launching the GUI and then opening them again when the GUI closes (this is not an acceptable solution... - for fairly obvious reasons!!)
I did think about trying to temporarily modify the shortcut key (Preferences-Keyboard-Shortcuts) of the "Evaluate Current Section" -> but haven't worked out a way to do it from the commandline, and then set it back again when finished. If this is fast you could do it when the user presses and releases the control key.
So what am I asking:
If possible I need a solution that will work for anyone anywhere - as if I can get this to work it will be included in a new add-on feature in my Matlab GUI Toolbox. - which is used by people all over the world.
Do you know how to modify the keyboard shortcuts from the commandline - if so how!
Any other suggestions?
My other idea is to change my shortcut to a different key combination - but wheres the fun in that! :) (I will still have the issue if some user somewhere has altered the execute the current cell to my new combination...)
P.S. Thanks for reading this far down!! :)
Why don't you go to the home> Preferences > keyboard > Shortcutand change it there?
you only need to hit Ctrl + Enter in the black box at top of the page for searching the related command, which is here Evaluate Current Section and change it whatever you like.
Please bear in mind you will only need to split out your windows (Undock them). Then, when you click on Ctrl + Enter, it will do whatever you would like.
I hope you find this answer helpful.
You can try the solution from my FEX submission. The KbTimer is motivated by the need to capture keyboard stroke without the need of GUI that designed either by GUIDE or APP DESIGNER. Note that the implementation of function was inspired from the PsychToolbox which is MEX based.
By default, Matlab binds F1 to the doc command. I'd like to change that binding to doc2, which is a function of mine. Unfortunately, the documentation is not very helpul with that matter.
Is there a simple way to achieve this ?
Thank you.
No, you can't do that, and MATLAB does not at all bind F1 to the doc command.
By default, F1 is bound to a few different things, depending on what desktop component you're using at the moment, and whether you have anything selected. In the MATLAB desktop, if nothing is selected, it will open up the Help Browser; but if something is selected, it will do Help on Selection instead, and if you're in the Genome Browser from Bioinformatics Toolbox, it will do something different again, specific to that tool.
You can modify those bindings in the MATLAB Preferences (Keyboard->Shortcuts); but you can only remap the bindings for existing actions, not create your own.
When the default action of opening up the Help Browser is carried out by a keyboard shortcut, it is not done by calling the doc command (that would be a bad idea, as the user may have modified or replaced the doc command to do something unrelated to help).
I am writing a GUI program with matlab and I would like to test my variables to see if they are properly imported and to test how to access to different parts of the variables imported so I want my variables to be shown in workspace window of Matlab desktop
the main trouble is if I write a common program in the mfile editor after running the program variables will be shown in workspace windows but about GUI programs its not true
And if I Save the workspace of my program from the path
File>Save Workspace As...
in MFile Editor and then I try to open this access file in desktop i encounter
No variables created
How can I accesss the workspace of my GUI?
If it is just for inspection, the easiest way is to use the debugger: set a breakpoint in one of the GUI callbacks, execution of the code halts there, and allows you to inspect the workspace, among other things.
If you want the GUI to return data to the main workspace, you add the line uiwait(hObject) to the end of the opening function. Then, the callback to e.g. the OK-button should have a line handles.Output=myData; guidata(hObject,handles); to send the variable myData to the GUI output, followed by uiresume(hObject). This way, you can call your GUI as myData = myGUI;, and myData in the base workspace will be filled with whatever data the OK-callback gives it once the OK-button is clicked.
Note: Functions assign outputs, not internal variables to the base workspace. So I guess what you describe as "functions in the editor" are actually scripts that access and modify the contents of the workspace from which they're called.