Separate tools setting callbacks for one event
古いコメントを表示
Consider two tools that add annotations to a plot. Both toolA and toolB add annotations that are sensitive to the current YLim of the axis. toolA and toolB are completely independent. Either one or both may be used on any given plot.
Both tools add annotations that must be placed relative to one another within their set. For example, a series of labels that "stair step" down as the x-axis increases. So the position of any individual label has some dependence on the "previous" label (text object).
I have found that just adding a listener on YLim PostSet is insufficient, as the "Restore View" for zoom does not stimulate that callback. I have found I also need the same callback(s) invoked if the figure size is changed. I am aware of the LimitsChanged callback for axis objects and the SizeChanged callback for the figure objects, but as far as I can tell they can only point to a single callback function, not a list of functions.
I have figured out some rather hacky ways to handle this use case, but I'm wondering if there is a preferred method for doing something like this. It seems that addlistener would be the preferred way as that doesn't overwrite a property, but I've been unable to find a way to get that to reliably work for all use cases (like zooming and figure resizing).
[Note that I am currently using R2022b, but there are others in our group that currently need to use MATLAB as old as R2018b. We have a number of mission-critical tools that need to be recertified if the version of MATLAB changes, so there can be lags adopting the lastest version of MATLAB.]
4 件のコメント
Matt J
2026 年 3 月 30 日 23:45
Jay St. Pierre
2026 年 3 月 31 日 21:44
Jay St. Pierre
2026 年 4 月 3 日 21:05
Jay St. Pierre
約10時間 前
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!