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?
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!