Make gca() responsive to appDesigner axes clicks

조회 수: 1 (최근 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 CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by