Make gca() responsive to appDesigner axes clicks
5 views (last 30 days)
Show older comments
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.

0 Comments
Accepted Answer
Voss
on 8 Mar 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)')
More Answers (0)
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!