Showing posts with label matlab. Show all posts
Showing posts with label matlab. Show all posts

October 28, 2018

MATLAB bug: Why does QUESTDLG return the wrong button string if I use the TAB key to switch between different buttons and then hit the Return key?


The UI MATLAB function questdlg has following issue:

If you use questdlg and use the TAB key to switch different button and press the ENTER key to validate your selection, the returned selected Button is always the Default button.

The issue is described in details in the Support Knowledge base 1-3MB2SF.

Below a short screencast to demonstrate it:
It is still not solved in MATLAB R2015b.
As mentioned in the Answer here, this issue can be fixed easily by adding/editing 2 lines in questdlg:
Change the KeyPressFcn callback to:

function cb_KeyPressFcn(obj,evd)
switch(evd.Key)
    case {'return','space'}
        ButtonName=get(get(figureHandle,'CurrentObject'),'String');
        setappdata(figureHandle,'ButtonName',ButtonName);
        uiresume(gcbf);
    case 'escape'
        doDelete
end

and after the uiwait change the line:

ButtonName=get(get(QuestFig,'CurrentObject'),'String');

into:

ButtonName=getappdata(figureHandle,'ButtonName');
if isempty(ButtonName), % no KeyPress/ MouseClick,
    ButtonName=get(get(figureHandle,'CurrentObject'),'String');
end


This fix is implemented in the myquestdlg available in my .


Note:

It is still required to used a drawnow after a myquestdlg call, because of some MATLAB hanging issues.


Related Posts:

MATLAB: How to find when a feature was introduced in MathWorks products?


Once I wanted to find when = in which MATLAB Release the Fast Restart feature of Simulink was introduced.
This post explains the way to find it out.
1.) Go to the MathWorks product documentation http://www.mathworks.com/help/
2.) Search for "fast restart" (with quotation marks around)
3.) On the left under "Refine by Product" select Simulink
4.) On the left under "Refine by Type" select Release Notes

Direct link looks like this: http://www.mathworks.com/help/search.html?qdoc=%22fast+restart%22+type%3Arn+product%3Asimulink



5.) Click on the one remaining search entry and you should find what you are looking for.

StackOverflow https://stackoverflow.com/questions/19778832/how-can-i-check-since-which-matlab-version-a-function-exists/36922759#36922759

FileExchange Utility when

MATLAB bug: How can I modify the INPUTDLG function to make the "Enter" key synonymous with the "OK" button?

It is quite annoying for the user that with the standard MATLAB input dialog (

) you can not validate your inputs by simply pressing the Enter key and have to click with the mouse on the "OK" button or the only way to close the dialog without using the mouse is to Tab through all of the fields until the OK button is active and then press "Enter".
The question was already asked to MathWorks support. This is the solution provided by MathWorks:
It is not very comfortable, since you have to copy a file into the MATLAB installation uitools subfolder.
Another solution is implemented in the function myinputdlg. This function is standalone and does not require the use of native uitools/private functions.
Besides you can press the "Space" key on the pushbuttons to activate them and the space KeyPress on the figure is not buggy anymore.

Related posts:

September 9, 2016

MathWorks Bug Transparency and MATLAB R2015b bug in fullfile

MathWorks Logo

There is a bug in MATLAB R2015b in the fullfile function:

>> fullfile('C:\', '\titi\toto.m')

ans =

C:\\titi\toto.m

See the doubled backslash after the drive letter (highlighted in red).

The function JoinPath by Jan Simon in the FileExchange fixes it.
Jan states his function is also faster. I haven't verified this but I trust him.

It seems this bug hasn't been reported yet (as of 2016-07-19/ I've just reported it).

After exchange with the MathWorks support, it seems this bug was reported but MathWorks does not publish all known bugs under http://www.mathworks.com/support/bugreports/. (I would have expected that.)

Below the explanation from MathWorks Support (answer date: 2016-07-20)

This bug is only registered internally and was not nominated for an external bug report.
...
There is a decision making process (including the 'nomination' I mentioned) involving considerations of how many customers might be impacted and the severity of the issue. In this specific case, you are the second customer worldwide coming to us since existence of the bug. We in Technical Support would not be able to convince Development, that this bug impacts a larger user base.

September 7, 2016

MATLAB Editor: customized Shortcuts

It is possible to add Shortcuts in the MATLAB Editor for customized actions. I take as example in this post the nice utility in the File Exchange plot_depfun.

1. Function returning current file in Editor

For this you need a utility function that returns the current opened file in the MATLAB Editor. You can find this function below: As you see this can be achieved in lines of code. (Credit to Yair Altman http://UndocumentedMatlab.com)

2. Adapt function to take as default input file the current file in the Editor

Then you need to adapt the function to be run by the Shortcut to take by default the current file in editor, calling previous utility function. You need to add something like the lines below:
if nargin==0 || isempty(foo),
    foo= EditorGetFile();
end
at the top of the file. (My full modified plot_depfun version is available in Gist here.)

3. Create the Shortcut

You can create a Shortcut in the MATLAB Toolbar as explained in the& MATLAB documentation. See screenshot below:
Screenshot - Create MATLAB Shortcut with "Add to quick access toolbar" selected
Create Shortcut with "Add to quick access toolbar"
Simply put a call to the plot_depfun function as Callback: this will take the current file in the Editor (see modification done in Step 2.) If you haven't implemented in the function the default used file as EditorGetFile (Step 2), you could also simply use here as Callback plot_depfun(EditorGetFile);. Important: Check the option "Add to quick access toolbar". This will make the Shortcut visible also in the MATLAB Editor as shown in next screenshot in the so-called Quick Access Toolbar:
Screenshot - Shortcut visible in MATLAB Editor Quick Access Toolbar
Shortcut is accessible from Editor Quick Access Toolbar
Hint 1: You can organize the Shortcuts (re-order, add separators etc.) by right-clicking on the Toolbar and select the last context menu entry "Customize...". Hint 2: The file located under fullfile(matlabroot, 'toolbox/matlab/icons','plotpicker-dendrogram.png') is used as icon for the plot_depfun shortcut.