Undocumented Matlab
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT

A couple of internal Matlab bugs and workarounds

June 12, 2013 4 Comments

Like any other major software package, Matlab too has its share of bugs. If you ask me, the number of known bugs in Matlab is actually very small compared to the industry standard. Posting bugs online saves the support staff work on duplicates and provides immediate relief for users if the bug happens to have a posted workaround. It also increases transparency, which helps customer loyalty and confidence in the product. Serious engineering work that relies on Matlab for anything from designing cars and planes to trading on stock exchanges needs to be aware of all the current bugs, in order to avoid them in the production code.
Unfortunately, for some reason MathWorks does not publicize all the bugs that it knows about. I know this since there are multiple bugs that I have reported and were confirmed by the competent technical support staff, which do not appear on the online list. I do not know whether this is a deliberate MathWorks policy based on some criteria, but I would hope not and I hope it will be fixed. IMHO, Matlab in general is a very stable system that has absolutely nothing to be ashamed of in terms of the low number, and relatively low-impact, of its open bugs.
Today I write about two internal Matlab bugs that I have recently discovered and reported, along with their workarounds. None of them is really critical, but since neither appears in the official bug parade (as of today), I figured it would do some public good to post them here.

The clf function does not clear javacomponents (1-MNELS1)

The clf function clears the specified figure window (or the current figure [gcf] if no figure handle was specified as input) of any axes and GUI controls. At least, that what it is supposed to do and what it did pretty well until R2012a (Matlab 7.14). Apparently, in R2012b (Matlab 8.0) something broke and controls that are added to the figure window using the javacomponent function are no longer cleared by clf – all the regular Matlab axes and uicontrols are deleted, but not the Java controls.

figure;
[jButton, hContainer] = javacomponent(javax.swing.JButton('Click'), [], gcf);
drawnow;
clf  % bug - clf does not delete the jButton/hContainer component from the figure

figure; [jButton, hContainer] = javacomponent(javax.swing.JButton('Click'), [], gcf); drawnow; clf % bug - clf does not delete the jButton/hContainer component from the figure

There are several possible workarounds:

  1. Keep the handles of all the relevant Java components, and then delete them directly:
    delete(hContainer)

    delete(hContainer)

  2. Use findobj to delete all components, rather than the clf function (we use setdiff to prevent deletion of the figure window itself):
    delete(setdiff(findobj(gcf),gcf))

    delete(setdiff(findobj(gcf),gcf))

Note that this bug does not occur when using HG2. However, for users who use the still-standard HG1, this bug is still unfixed as of Matlab R2013b Pre-release (which is now available for download for subscribed users).

GUIDE is unusable with dbstop if error (1-MH5KVI)

In R2013a (Matlab 8.1) I encounter a recurring error when attempting to inspect properties of objects in GUIDE, when “dbstop if error” is turned on.
The error happens when I have “dbstop if error” enabled. This is an enormously helpful debugging tool, so I normally have it turned on in my startup.m file. But in R2013a, if I try to inspect an object’s properties in GUIDE, I see a problem. Matlab hits the breakpoint in %matlabroot%/toolbox/matlab/codetools/+internal/+matlab/+inspector/SceneViewerListener.m line 99 due to the fact that isvalid() is not defined for the object, and the inspector window remains blank.
How to reproduce:

  • run “dbstop if error” in the Matlab command window
  • open a *.fig file in the Matlab command window (e.g., “guide myApplication.fig“)
  • right-click and inspect the properties for an axes (for example)
  • wait for the breakpoint to occur – “K>>” in the command window; the Editor stops (green arrow) in SceneViewerListener.m line 99
  • an empty inspector window is displayed

Analysis:
Because SceneViewerListener is called from Java, not Matlab, the error is thrown as an exception that is trapped by the Java code and therefore does not appear to the user unless “dbstop if error” is on. Here is the full stack trace at the point of error (see this post regarding how to generate the Java stack dump):

K>> dbstack
> In SceneViewerListener>SceneViewerListener.isBeingDeleted at 99
K>> st = java.lang.Thread.currentThread.getStackTrace; for idx = 2 : length(st), disp(st(idx)); end
com.mathworks.jmi.NativeMatlab.SendMatlabMessage(Native Method)
com.mathworks.jmi.NativeMatlab.sendMatlabMessage(NativeMatlab.java:219)
com.mathworks.jmi.MatlabLooper.sendMatlabMessage(MatlabLooper.java:120)
com.mathworks.jmi.Matlab.mtFeval(Matlab.java:1540)
com.mathworks.mlwidgets.inspector.JidePropertyViewTable.isBeingDeleted(JidePropertyViewTable.java:154)
com.mathworks.mlwidgets.inspector.JidePropertyViewTable.filterOutInvalidObjects(JidePropertyViewTable.java:170)
com.mathworks.mlwidgets.inspector.JidePropertyViewTable.setObjects_MatlabThread(JidePropertyViewTable.java:187)
com.mathworks.mlwidgets.inspector.PropertyView.setObject_MatlabThread(PropertyView.java:655)
com.mathworks.mlwidgets.inspector.PropertyView.setObject_AnyThread(PropertyView.java:591)
com.mathworks.mlwidgets.inspector.PropertyView.access$1300(PropertyView.java:37)
com.mathworks.mlwidgets.inspector.PropertyView$RegistryHandler.itemStateChanged(PropertyView.java:698)
java.awt.AWTEventMulticaster.itemStateChanged(Unknown Source)
com.mathworks.services.ObjectRegistry.fireItemEvent(ObjectRegistry.java:763)
com.mathworks.services.ObjectRegistry.setSelected(ObjectRegistry.java:700)
com.mathworks.services.ObjectRegistry.setSelected(ObjectRegistry.java:617)
com.mathworks.mde.inspector.Inspector.setSelected(Inspector.java:584)
com.mathworks.mde.inspector.Inspector.inspectObjectArray(Inspector.java:569)
com.mathworks.mde.inspector.Inspector.inspectObjectArray(Inspector.java:520)
com.mathworks.mde.inspector.Inspector$11.run(Inspector.java:478)
com.mathworks.jmi.NativeMatlab.dispatchMTRequests(NativeMatlab.java:347)

K>> dbstack > In SceneViewerListener>SceneViewerListener.isBeingDeleted at 99 K>> st = java.lang.Thread.currentThread.getStackTrace; for idx = 2 : length(st), disp(st(idx)); end com.mathworks.jmi.NativeMatlab.SendMatlabMessage(Native Method) com.mathworks.jmi.NativeMatlab.sendMatlabMessage(NativeMatlab.java:219) com.mathworks.jmi.MatlabLooper.sendMatlabMessage(MatlabLooper.java:120) com.mathworks.jmi.Matlab.mtFeval(Matlab.java:1540) com.mathworks.mlwidgets.inspector.JidePropertyViewTable.isBeingDeleted(JidePropertyViewTable.java:154) com.mathworks.mlwidgets.inspector.JidePropertyViewTable.filterOutInvalidObjects(JidePropertyViewTable.java:170) com.mathworks.mlwidgets.inspector.JidePropertyViewTable.setObjects_MatlabThread(JidePropertyViewTable.java:187) com.mathworks.mlwidgets.inspector.PropertyView.setObject_MatlabThread(PropertyView.java:655) com.mathworks.mlwidgets.inspector.PropertyView.setObject_AnyThread(PropertyView.java:591) com.mathworks.mlwidgets.inspector.PropertyView.access$1300(PropertyView.java:37) com.mathworks.mlwidgets.inspector.PropertyView$RegistryHandler.itemStateChanged(PropertyView.java:698) java.awt.AWTEventMulticaster.itemStateChanged(Unknown Source) com.mathworks.services.ObjectRegistry.fireItemEvent(ObjectRegistry.java:763) com.mathworks.services.ObjectRegistry.setSelected(ObjectRegistry.java:700) com.mathworks.services.ObjectRegistry.setSelected(ObjectRegistry.java:617) com.mathworks.mde.inspector.Inspector.setSelected(Inspector.java:584) com.mathworks.mde.inspector.Inspector.inspectObjectArray(Inspector.java:569) com.mathworks.mde.inspector.Inspector.inspectObjectArray(Inspector.java:520) com.mathworks.mde.inspector.Inspector$11.run(Inspector.java:478) com.mathworks.jmi.NativeMatlab.dispatchMTRequests(NativeMatlab.java:347)

Workaround:
replace the existing code of SceneViewerListener.m:

>> edit internal.matlab.inspector.SceneViewerListener
...
if ~isvalid(selectedObject)
    beingDeleted = true;
elseif isprop(selectedObject,'BeingDeleted') && strcmp('on',selectedObject.BeingDeleted)
    beingDeleted = true;
elseif ~isempty(ancestor(selectedObject,'figure')) && strcmp('on',get(ancestor(selectedObject,'figure'),'BeingDeleted'))
    beingDeleted = true;
else
    beingDeleted = false;
end

>> edit internal.matlab.inspector.SceneViewerListener ... if ~isvalid(selectedObject) beingDeleted = true; elseif isprop(selectedObject,'BeingDeleted') && strcmp('on',selectedObject.BeingDeleted) beingDeleted = true; elseif ~isempty(ancestor(selectedObject,'figure')) && strcmp('on',get(ancestor(selectedObject,'figure'),'BeingDeleted')) beingDeleted = true; else beingDeleted = false; end

with the following (changed lines are highlighted):

if any(~isobject(selectedObject))    beingDeleted = false;elseif ~isValid    beingDeleted = true;
elseif isprop(selectedObject,'BeingDeleted') && strcmp('on',selectedObject.BeingDeleted)
    beingDeleted = true;
elseif ~isempty(ancestor(selectedObject,'figure')) && strcmp('on',get(ancestor(selectedObject,'figure'),'BeingDeleted'))
    beingDeleted = true;
else
    beingDeleted = false;
end

if any(~isobject(selectedObject)) beingDeleted = false; elseif ~isValid beingDeleted = true; elseif isprop(selectedObject,'BeingDeleted') && strcmp('on',selectedObject.BeingDeleted) beingDeleted = true; elseif ~isempty(ancestor(selectedObject,'figure')) && strcmp('on',get(ancestor(selectedObject,'figure'),'BeingDeleted')) beingDeleted = true; else beingDeleted = false; end

It looks like this bug was apparently fixed in the R2013b Pre-release without needing to modify SceneViewerListener. But if you still encounter this problem you now know what to do.
I have reported another GUIDE-related bug, but I do not have a workaround for this one: If you run the GUI from within GUIDE, and some uncaught error (exception) occurs, then from that moment onward you cannot save any modifications to the figure file in that session.
Do you know of any other undocumented bugs, preferably with workarounds? If so, please post them in a comment here.

Related posts:

  1. Another couple of Matlab bugs and workarounds – A couple of internal Matlab bugs and their workarounds. ...
  2. Matlab's internal memory representation – Matlab's internal memory structure is explored and discussed. ...
  3. Internal Matlab memory optimizations – Copy-on-write and in-place data manipulations are very useful Matlab performance improvement techniques. ...
  4. Accessing internal Java class members – Java inner classes and enumerations can be used in Matlab with a bit of tweaking. ...
  5. Graphic sizing in Matlab R2015b – Matlab release R2015b's new "DPI-aware" nature broke some important functionality. Here's what can be done... ...
  6. Matlab compiler bug and workaround – Both the Matlab compiler and the publish function have errors when parsing block-comments in Matlab m-code. ...
Bug GUI GUIDE Pure Matlab Undocumented feature
Print Print
« Previous
Next »
4 Responses
  1. Dan June 12, 2013 at 18:14 Reply

    I’m not sure if this is an error or a feature that I’m not comprehending…

    I’ve started playing around with using Mask Objects (http://www.mathworks.com/help/simulink/slref/simulink.mask.get.html) from a Simulink Mask instead of using the old reliable

     MaskValues = get_param(gcb,'MaskValues')

    MaskValues = get_param(gcb,'MaskValues')

    , etc…
    I have a dialog callback that gets that Mask Object. The problem is the Mask Object it gives you gives parameters for the Mask BEFORE it was opened, and does not include changes that you have made to the mask since opening the simulink GUI. (i.e. My dialog callback is working with old data).
    My Fix: ??, go back to old reliable.

    • Donn Shull June 15, 2013 at 09:03 Reply

      I agree that the disparity between these two values is odd. I might consider it as a feature and explain it as follows.

      Dialog Values = get_param(gcb,'MaskValues')

      Dialog Values = get_param(gcb,'MaskValues')

      returns the values from the dialog for the mask even if they have not been “applied”

      BlockMask = Simulink.Mask.get(gcb)
      MaskValues = BlockMask.Parameters

      BlockMask = Simulink.Mask.get(gcb) MaskValues = BlockMask.Parameters

      returns the mask parameters that are being used by the block.

  2. Andrew June 14, 2013 at 15:32 Reply

    I’ve noticed this as well. I find it unhelpful as a developer. It can be useful to know if a bug exists and/or has been fixed in a particular version. This way one can apply workarounds if needed in code used by people who may be running many different versions of Matlab.

    For example, Matlab 7.14 (R2012a), 7.13 (R2011b), and probably earlier, has a bug in the inverse complementary error function, erfcinv, where erfcinv(eps(realmin)) returns NaN instead of a finite real value as would be expected and as indicated by the documentation (this occurs in single precision as well). I reported this bug and suggested a simple “workaround.” The bug was acknowledged and I even suggested how it might be fixed when the engineer explained the reason for the underflow. The bug was fixed in Matlab 8.0 (R2012b), but it never showed up in the online database so you’d never know that it exists/existed.

    By the way, here is code that will apply a workaround in pre-R2012b versions:

    x = erfcinv(y);
    if verLessThan('matlab','8.0')
        if isa(p,'double')
            x(y == 2^-1074) = 27.216482834230213;
        else
            x(y == 2^-149) = 10.0198345;
        end
    end

    x = erfcinv(y); if verLessThan('matlab','8.0') if isa(p,'double') x(y == 2^-1074) = 27.216482834230213; else x(y == 2^-149) = 10.0198345; end end

    Of course verLessThan only goes back to Matlab 7.4 (R2007a), but that’s as far back as I try to retain support…

  3. Another couple of Matlab bugs and workarounds | Undocumented Matlab December 10, 2014 at 15:56 Reply

    […] mind, I don’t take it personally, I simply find a workaround and move on. I’ve already posted about this before. Today I’ll discuss two additional bugs I’ve run across once-too-often, and my […]

Leave a Reply
HTML tags such as <b> or <i> are accepted.
Wrap code fragments inside <pre lang="matlab"> tags, like this:
<pre lang="matlab">
a = magic(3);
disp(sum(a))
</pre>
I reserve the right to edit/delete comments (read the site policies).
Not all comments will be answered. You can always email me (altmany at gmail) for private consulting.

Click here to cancel reply.

Useful links
  •  Email Yair Altman
  •  Subscribe to new posts (feed)
  •  Subscribe to new posts (reader)
  •  Subscribe to comments (feed)
 
Accelerating MATLAB Performance book
Recent Posts

Speeding-up builtin Matlab functions – part 3

Improving graphics interactivity

Interesting Matlab puzzle – analysis

Interesting Matlab puzzle

Undocumented plot marker types

Matlab toolstrip – part 9 (popup figures)

Matlab toolstrip – part 8 (galleries)

Matlab toolstrip – part 7 (selection controls)

Matlab toolstrip – part 6 (complex controls)

Matlab toolstrip – part 5 (icons)

Matlab toolstrip – part 4 (control customization)

Reverting axes controls in figure toolbar

Matlab toolstrip – part 3 (basic customization)

Matlab toolstrip – part 2 (ToolGroup App)

Matlab toolstrip – part 1

Categories
  • Desktop (45)
  • Figure window (59)
  • Guest bloggers (65)
  • GUI (165)
  • Handle graphics (84)
  • Hidden property (42)
  • Icons (15)
  • Java (174)
  • Listeners (22)
  • Memory (16)
  • Mex (13)
  • Presumed future risk (394)
    • High risk of breaking in future versions (100)
    • Low risk of breaking in future versions (160)
    • Medium risk of breaking in future versions (136)
  • Public presentation (6)
  • Semi-documented feature (10)
  • Semi-documented function (35)
  • Stock Matlab function (140)
  • Toolbox (10)
  • UI controls (52)
  • Uncategorized (13)
  • Undocumented feature (217)
  • Undocumented function (37)
Tags
AppDesigner (9) Callbacks (31) Compiler (10) Desktop (38) Donn Shull (10) Editor (8) Figure (19) FindJObj (27) GUI (141) GUIDE (8) Handle graphics (78) HG2 (34) Hidden property (51) HTML (26) Icons (9) Internal component (39) Java (178) JavaFrame (20) JIDE (19) JMI (8) Listener (17) Malcolm Lidierth (8) MCOS (11) Memory (13) Menubar (9) Mex (14) Optical illusion (11) Performance (78) Profiler (9) Pure Matlab (187) schema (7) schema.class (8) schema.prop (18) Semi-documented feature (6) Semi-documented function (33) Toolbar (14) Toolstrip (13) uicontrol (37) uifigure (8) UIInspect (12) uitable (6) uitools (20) Undocumented feature (187) Undocumented function (37) Undocumented property (20)
Recent Comments
Contact us
Captcha image for Custom Contact Forms plugin. You must type the numbers shown in the image
Undocumented Matlab © 2009 - Yair Altman
This website and Octahedron Ltd. are not affiliated with The MathWorks Inc.; MATLAB® is a registered trademark of The MathWorks Inc.
Scroll to top