Make gca() responsive to appDesigner axes clicks

2 Ansichten (letzte 30 Tage)
Matt J
Matt J am 8 Mär. 2025
Kommentiert: Voss am 8 Mär. 2025
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.

Akzeptierte Antwort

Voss
Voss am 8 Mär. 2025
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 Kommentare
Matt J
Matt J am 8 Mär. 2025
That worked (thank god).
Voss
Voss am 8 Mär. 2025
Glad to hear it!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Produkte


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by