Make gca() responsive to appDesigner axes clicks

4 ビュー (過去 30 日間)
Matt J
Matt J 2025 年 3 月 8 日
コメント済み: Voss 2025 年 3 月 8 日
I have an appdesigner app such as below with a uipanel containing regular images (not uiimages). I also have many, many standalone mfunctions from before the days of appdesigner for manipulating displayed images. I would now like to apply these utility mfunctions to images in the app window that I click on. However, the mfunctions were written to freely call gca() to obtain the axis last clicked. Now, I am discovering that gca() will not detect button clicks on images plotted in uifigures. Is there no way to have the app update the current axis so that gca() can detect clicks in the app window? I would much prefer not to have to rewrite all my functions.

採用された回答

Voss
Voss 2025 年 3 月 8 日
All you might have to do is to set the app's UIFigure's HandleVisibility to 'callback' (or 'on'), because gca() calls gcf() and a (ui)figure with HandleVisibility 'off' will never be the groot 'CurrentFigure'.
Here's some code provided as proof-of-concept. Clicking on any image will display its axes to the command-line.
f = uifigure('HandleVisibility','callback');
ax = [uiaxes(f) uiaxes(f)];
set(ax,{'Position'},{[10 10 500 200];[10 220 500 200]})
im = [image(ax(1)) image(ax(2))];
set(im,'ButtonDownFcn','disp(gca)')
  2 件のコメント
Matt J
Matt J 2025 年 3 月 8 日
That worked (thank god).
Voss
Voss 2025 年 3 月 8 日
Glad to hear it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by