How to prevent error on zoom tool after clicking reset view with linked axes?
3 views (last 30 days)
Show older comments
Hi,
Procdedure:
- a figure is created from an appdesigner GUI (a figure, not a uifigure) with two axes, in one an image is plotted, in the other a line plot is plotted
- the axes are linked via linkaxes( [HAx1, HAX2], 'x')
- when using the scroll wheel of the mouse, I can zoom in and out of the image, the line plot's axes changes XLim accordingly -> works
- clicking the 'Restore View' icon
- with the zoom tool not selected, zooming via the scroll wheel of the mouse works (linked axes also changes)
- with the zoom tool selected, zooming (clicking, using scroll wheel or drawing zoom rectangle) throws the error message
Invalid or deleted object.
Error in zoom>localStoreLimits (line 636)
if
isa(linkAxesInfo.LinkProp,'matlab.graphics.internal.LinkProp')
Error in zoom>localButtonWheelFcn (line 867)
localStoreLimits(hAxes(i));
Error in
zoom>@(obj,evd)localButtonWheelFcn(obj,evd,hMode)
(line 533)
set(hMode,'WindowScrollWheelFcn',@(obj,evd)localButtonWheelFcn(obj,evd,hMode));
Error while evaluating Figure WindowScrollWheelFcn.
In our GUI, the procedure to create the figure and the plots is more elaborate, which is why I do not post the code here. Unfortunately, I tried a MWE but could not reproduce the error (I know, this does not help).
I looked around the zoom.m function and at the specific line where the error is thrown. I saved the variable linkAxesInfo from line
% zoom.m line #636
linkAxesInfo = getappdata(hAxes,'graphics_linkaxes');
to the base workspace when the zoom was still working. When the error is thrown, the field linkAxesInfo.LinkProp is indeed invalid as the error states. Now the curious part, if the variable exists in the workspace, the error does not occur. As soon as the variable is cleared, the error is thrown.
So to me it seems, that the function called by clicking 'Restore View' somehow screws up the data in the appdata. Maybe that the reference to the listener changing the axes is lost und thus the listener is deleted ...
Does anybody have an idea what is going on? Or what I could do to prevent this from happening?
I will simplify the actual GUI/code to post it, but I thougt maybe someone already has an idea of what is going on.
I also tried the suggestions from Yair Undocumented MATLAB: using-linkaxes-vs-linkprop of using the linkprop method, but that shows the same error (maybe because the property-change listener is also stored in the appdata).
In short, with linked plots, why can using the 'Restore View' icon result in an error when using the zoom tool (but zooming without the zoom tool being activated works)?
Thanks for your help!
Henning
Update 1:
I just noticed, there is already a bug report with probably this error https://www.mathworks.com/support/bugreports/2049202?s_tid=answers_rc2-1_p4_MLT
% MWE
ax1 = subplot(2,1,1);
legend(ax1)
ax2 = subplot(2,1,2);
legend(ax2)
linkaxes([ax1 ax2])
Answers (0)
See Also
Categories
Find more on Data Exploration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!