필터 지우기
필터 지우기

image callback in app designer

조회 수: 17 (최근 30일)
Gordon Edwards
Gordon Edwards 2019년 6월 25일
댓글: Guillaume 2019년 6월 25일
I have an app with a UIAxes which contains an image with the returned image object im i.e.im=image(UIAxesObject, array). I create a buttondownfcn callback using
im.ButtonDownFcn = @FCN. However, if I create the function FCN(app, event) inside the private or public function area of the app designer I get an error. The only way I seem to be able to get the callback to work is to put function FCN in a separate m. file. Is there another way of creating callback functions in app designer?
  댓글 수: 2
Guillaume
Guillaume 2019년 6월 25일
I get an error
What is the full text of the error message?
Gordon Edwards
Gordon Edwards 2019년 6월 25일
The error message is when the callback function is a private method is ---
Undefined function 'ImageButtonDownCallBack' for input
arguments of type 'matlab.graphics.primitive.Image'.
Error while evaluating Image ButtonDownFcn.

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2019년 6월 25일
You may want to consider using a uiimage instead of an Image inside a uiaxes.
I suspect you've defined the callback incorrectly. Typically the code would be something likle
classdef myapp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
UIAxes matlab.ui.control.UIAxes
%... other controls. You can't edit this directly
end
%your own properties
properties (Access = private)
myimage; %property to hold the image
end
%...
methods (Access = private)
function ImageButtonDownCallback(app, source, eventargs)
%... the callback code
end
%The function that creates the image and enable the callback
function something(app)
app.myimage = imshow(someimage, 'Parent', app.UIAxes); %image creation
app.myimage.ButtonDownFcn = @app.ImageButtonDownCallback; %create callback. IMPORTANT: You must use app.****
end
end
end
  댓글 수: 2
Gordon Edwards
Gordon Edwards 2019년 6월 25일
Thankyou - that works fine. I hadn't realised that the syntax @app.ImageButtonDownCallback is required.
I use the image function as I am creating one in UIAxes from an array. I find MatLab's nomenclature confusing at times - for example, use of the word 'image' as a function displaying an image from an array and also, in app designer, for an icon.
Guillaume
Guillaume 2019년 6월 25일
Indeed, you have:
  • the image function
  • the image type, returned by image, imshow, imagesc and probably other functions. The full name of that type is actually matlab.graphics.primitive.Image. It's not really well documented. The only doc page is its property page.
  • the app designer image control whose full name is matlab.ui.control.Image. Again, not very well documented. It has a different set of properties and callbacks from the previous image type.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by