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).
Related
When the cursor's positioned in the middle of an argument list (making a method call), is there a way to bring up the method's signature with the parameter that that the cursor is on highlighted? Ctrl-space (sort of) brings up the signature, but it includes the huge search list of everything else I can legally type right there, and it's up to me to count through the arguments and the parameters to figure out which one I'm lined up on. (that popup also disappears if I try to move to the next or previous argument).
I've had this struggle with compiled code, and worse with code as I type it in. I typically type the name of the object, then a dot, and then I wait for the signature list to pop up (that filters down as I type). When I see the signature I'm after, I auto-complete with tab or Enter, and then I always end up in a struggle. NB pastes in variable names that are usually about 99% wrong, and I try to navigate the little red, comma-triggered edit boxes, hoping the signature popup will stay in view while I struggle to edit, delete (and stop thinking about) all the (semantic) errors. I usually end up botching it and loose the precious signature window that highlights each parameter as I moved through the argument list.
Any way to get that thing back (with the parameter highlighting)? And/or make the red editing boxes go away? And/or block NB from populating with all the errors?
Super thankful for any help or tips!
Netbeans show popup with method signatures and popup with method documentation only when your cursor is placed at the name of a method. Popup is displayed automatically when writing method name or on demand if you press Ctrl+Space.
When your cursor is placed at the argument list, only parameter names from method signature are displayed in form of a small tooltip. You can force display of this tooltip by Ctrl+P. Unfortunately there is no way how to invoke popup with method documentation in this phase. Instead you will see documentation popups related to arguments which you will type into the method argument list. The only way to display method documentation again is to place the cursor back at the method name and press Ctrl+Space.
When you start writing a method name, popup with method signatures will emerge. When you select one of proposed method signatures by pressing Enter, Netbeans will autocomplete method name as well as its arguments. You find this uncomfortable, because names of autocompleted arguments are usually wrong. You can however easily navigate between autocompleted arguments using Tab and Shift+Tab and overwrite them as you like. Alternatively, you can use Tab instead of Enter when selecting method from method signatures popup. This way Netbeans will autocomplete only the name of the function, not its arguments.
Described Netbeans behavior applies to editing PHP code, and may differ slightly for other languages.
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.
I'm using the %% command to split my code into blocks for the sake of readability,
I collapse those blocks when i'm not working in them.
The default settings don't give you the ability to fold them, so my first question is:
Can you tweak this setting by command, so anyone who opens my script has the option to fold them?
My second question is: Can I program my code to set the blocks as collapsed by default?
Thanks in advance
It is indeed possible
1) Type preference in the command window to get up the preferences menu (or you find in under home)
2) Go to Editor/Debugger -> Code Folding
3) Mark the enable box for Sections
You could wrap your sections in the following way:
%% //Section header
for folding=true
%// Your code here
end %//folding
This allows you to fold on the for "loop".
It will work for everybody who has a fairly recent Matlab editor, without messing with editor settings.
Note that you should not have an actual variable named folding.
Yes, this is entirely possible:
com.mathworks.services.Prefs.setBooleanPref('EditorMCodeFoldEnabledcell', true);
The command takes effect immediately. Find more information in the article Changing system preferences programmatically.
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.
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).