Problem with addlistener to xlim

3 次查看(过去 30 天)
I have a routine which needs to execute automatically every time the axis limits change in a plot. I have accomplished this by adding a listener with a callback function which updates the plot as required:
addlistener(axhdl, 'YLim', 'PostSet', @yaxisrescale)
My problem is that this solution only seems to work in HG2 (2014B, Win7) when the axis scaling is set explicitly, as in:
ylim([0,1]);% callback is properly triggered
If ylim is called with the 'auto' option the callback function is not triggered even if the axis was rescaled as a result of the call to ylim.
ylim('auto');% callback is not triggered - even if the axis is rescaled as a result of the call
Can anybody explain why this is happening and even better how to guarantee that every time the axis limits are changed my callback will be triggered?

采纳的回答

Tushar Sinha
Tushar Sinha 2015-7-30
编辑:Tushar Sinha 2015-7-30
Hi Jon,
It is my understanding that you wish to know why the callback is not triggered when the axis limits are changed using the "ylim('auto')" command in MATLAB R2014b. I also understand that you wish to know if there is a workaround to achieve this.
This behavior is as expected. When MATLAB R2014b is automatically calculating the limits, the limits frequently change several times as MATLAB inspects each member of the axes and updates the limits. Allowing listeners to be triggered during the automatic calculation (even if no listener was attached) would have caused performance degradation for all users (even if they are not using listeners), so the ability to trigger listeners with automatically calculated property value changes was disabled for performance reasons.
However, in MATLAB R2014a, the callback is triggered even when the ylim mode is set to "auto". If you have this version of MATLAB you can achieve the desired behavior. There are no workarounds as of now for MATLAB R2014b. I work for Mathworks and I have forwarded this feedback to the appropriate product team.
Thanks,
Tushar
  1 个评论
jvc
jvc 2015-7-30
Tushar, Thanks for the information - I thought this behavior used to be different prior to 2014B but I was not certain. Do you know if there is some other property to which the listener could be pointed in order to assure that my callback would be triggered when the axes are updated via ylim('auto')? Thanks

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by