Background
In previous versions of MATLAB (e.g. R2013b), I had a neat trick where I would attach a listener to an axes handle's YLim
property, which would notify me when the axes y-limits were changed:
addlistener(gca, 'YLim', 'PreSet', @(src,ev_data) disp(ev_data.NewValue))
I was using this to update a second figure which would show some summary statistics of the subset of data visible in these axes. And that was awesome! You zoom in, and the second figure updates itself. Great.
Making it a PreSet
(rather than PostSet
) listener was useful because then I could check if the new value was the same as the old value, and thus avoid recomputing these statistics when unnecessary.
The problem
However, this no longer works for me in R2014b. I'm able to attach the event listener, but when I trigger the event, I get this error message:
No appropriate method, property, or field NewValue for class event.PropertyEvent.
I believe this has something to do with the HG2 graphics system. With an appropriate breakpoint, we can look at the event data. In R2013b:
K>> ev_data
ev_data =
handle.PropertySetEventData
K>> get(ev_data)
Type: 'PropertyPreSet'
Source: [1x1 schema.prop]
AffectedObject: [1x1 axes]
NewValue: [0.5000 220.5000]
In R2014b, we seem to be missing the NewValue
field:
K>> ev_data
ev_data =
PropertyEvent with properties:
AffectedObject: [1x1 Axes]
Source: [1x1 matlab.graphics.internal.GraphicsMetaProperty]
EventName: 'PreSet'
Where did it go?! Surely there must be a way to access it. A property pre-set event handler is kinda useless if you can't access the new value you're trying to set it to.
NewValue
really is gone, and I'll have to work around it. – Cum